如何將一張圖像添加到UITableView
的多個單元?如何在UITableView單元上添加圖像?
我的圖像添加到一個頂電池,這樣的:
但滾動後的底部和頂部的我看到這一點:
第二和第三單元有一個z-index更多的是第一個單元格。
我該怎麼做?
謝謝..
如何將一張圖像添加到UITableView
的多個單元?如何在UITableView單元上添加圖像?
我的圖像添加到一個頂電池,這樣的:
但滾動後的底部和頂部的我看到這一點:
第二和第三單元有一個z-index更多的是第一個單元格。
我該怎麼做?
謝謝..
,如果你想添加的的tableView的圖像,使用tableviewobj.scrollview得到的tableview中滾動視圖的實例,然後將圖像添加爲子視圖上滾動視圖,並使用bringsubviewtofront方法圖像來前。
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;
}
試試這個代碼....
,並調整圖像大小....
將您的細胞高度調整爲圖像大小。
您是將圖像添加到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];
}
如果你想在單元格中添加圖像,那麼我會建議你使用imageView來製作自定義單元格。
可以作爲子視圖添加圖片到表
UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(3,2, 20, 25)];
imgView.image=[UIImage imageNamed:@"img.png"];
[UITableview addSubview:imv];
或
可以增加細胞
的高度我做到了。
img1
)對象的UITableView(table1
)img1.Layer.ZPosition
爲1,該圖像是上述細胞在table1
img1.Layer.ZPosition
到2,一個頭部在圖像上方謝謝大家的幫助!
您不會將它添加到單個單元格,而是添加到tableview本身。然後 - 在tableview子類中 - 您可以確保在layoutSubviews中圖像視圖保持在頂部,位置得到調整以保持在固定的位置。或者如果你想要的話,在特定的單元格旁邊。
直接在tableview上使用addSubview。
let imageView = UIImageView(frame: CGRectMake(0, 0, width, height))
imageView.image = UIImage(named: "My Image")
self.tableView.addSubview(imageView)
根據圖像高度 –
@maxname創建視圖,並通過提供X,Y值...... –
添加在表視圖我認爲你的問題解決了使用Custome細胞調節單元格高度。 – kb920