2012-04-10 44 views
0

我想把图像放在UITableViewCell中。我使用SSMessages样式作为我的消息。 enter image description hereUIImage在UITableViewCell

尝试了一些像cell.imageView.image = [UIImage imageNamed:message.messageText];但它是行不通的。有什么建议么?也许需要我的其他代码?

回答

3

使用SSMessageTableViewCellBubbleView的leftBackgroundImage和这种方式添加到您的表视图

SSMessageTableViewCellBubbleView *imageBubbleView = [SSMessageTableViewCellBubbleView alloc]  init]; 
imageBubbleView. leftBackgroundImage = [UIImage imageNamed:message.messageText]; 

[cell.contentView addSubview:imageBubbleView]; 

我希望这个工作!

1

首先设置图像视图的背景色进行故障排除:

cell.imageView.backgroundColor = [UIColor colorWithRed:(255.0f/255.0f) green:(0.0f/255.0f) blue:(0.0f/255.0f) alpha:1.0f]; 

设置图像:

cell.imageView.image = ...; 

设置图像视图帧:

cell.imageView.frame = CGRectMake(x, y, cell.imageView.image.size.width, cell.imageView.image.size.height); 

添加图像视图作为单元格的子视图。

把这个子视图前:

[cell bringSubviewToFront:[cell.imageView superview]]; 
1

您可能需要调用[cell setNeedsLayout][cell setNeedsDisplay],以获得细胞更新UIImageView的框架的新形象。如果UIImageView的框架是CGRectZero,简单地设置UIImageView上的图像将不会执行任何操作。

要查看是否该帧是零,尝试添加使用背景颜色或层边界:

cell.imageView.layer.borderWidth = 1.f; 
cell.imageView.layer.borderColor = [UIColor redColor].CGColor; 
相关问题