2013-08-19 32 views
0

如何將一張圖像添加到UITableView的多個單元如何在UITableView單元上添加圖像?

我的圖像添加到一個頂電池,這樣的:

screenshot

但滾動後的底部和頂部的我看到這一點:

screenshot

第二和第三單元有一個z-index更多的是第一個單元格。

我該怎麼做?

謝謝..

+0

根據圖像高度 –

+0

@maxname創建視圖,並通過提供X,Y值...... –

+0

添加在表視圖我認爲你的問題解決了使用Custome細胞調節單元格高度。 – kb920

回答

0

,如果你想添加的的tableView的圖像,使用tableviewobj.scrollview得到的tableview中滾動視圖的實例,然後將圖像添加爲子視圖上滾動視圖,並使用bringsubviewtofront方法圖像來前。

1
UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(3,2, 20, 25)]; 
imgView.image=[UIImage imageNamed:@"img.png"]; 
[cell addSubview:imv]; 

既可以直接添加圖像的細胞

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath 
{  
    static NSString* CellIdentifier = @"Cell"; 

    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
     cell = [[[UITableViewCell alloc] UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 

    cell.textLabel.text = @"I'm a UITableViewCell!"; 
    cell.imageView.image = [UIImage imageNamed:@"image.png"]; 

    return cell; 
} 

試試這個代碼....

,並調整圖像大小....

0

將您的細胞高度調整爲圖像大小。

1

您是將圖像添加到CellView還是添加到TableView?

您可以嘗試以下功能,您必須在其中指定文件名,圖片的位置,大小和視圖以將其添加到其中。

- (void)createImage:(NSString *)name 
        inX:(NSInteger)x 
        inY:(NSInteger)y 
       width:(NSInteger)w 
       height:(NSInteger)h 
        view:(UIView *)v{ 

    UIImage *background = [UIImage imageNamed:name]; 
    CGRect rect = CGRectMake(x, y, w, h); 
    UIImageView *yourImageView = [[UIImageView alloc] initWithFrame:rect]; 
    yourImageView.image = background; 
    [v addSubview:yourImageView]; 
} 
0

如果你想在單元格中添加圖像,那麼我會建議你使用imageView來製作自定義單元格。

0

可以作爲子視圖添加圖片到表

UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(3,2, 20, 25)]; 
imgView.image=[UIImage imageNamed:@"img.png"]; 
[UITableview addSubview:imv]; 

可以增加細胞

的高度
0

我做到了。

  1. 添加的UIImageView(比方說img1)對象的UITableView(table1
  2. 設置img1.Layer.ZPosition爲1,該圖像是上述細胞在table1
  3. 對於集管在表中的段設置img1.Layer.ZPosition到2,一個頭部在圖像上方

謝謝大家的幫助!

0

您不會將它添加到單個單元格,而是添加到tableview本身。然後 - 在tableview子類中 - 您可以確保在layoutSubviews中圖像視圖保持在頂部,位置得到調整以保持在固定的位置。或者如果你想要的話,在特定的單元格旁邊。

0

直接在tableview上使用addSubview。

let imageView = UIImageView(frame: CGRectMake(0, 0, width, height)) 
imageView.image = UIImage(named: "My Image") 
self.tableView.addSubview(imageView) 
相關問題