如何配合
UIImage
进入的单元格
UITableView
,uiTableViewCell(?).
你…吗
addSubview
到
cell
或者有调整大小的方法吗
cell.image
或
紫外图像
在分配给
细胞图像
?
我想保留单元格大小的默认值(无论初始化时是什么样的零矩形),并想在每个条目中添加类似图标的图片。图像略大于单元格大小(表格行大小)。
我想代码看起来像这样(从我的头上看):
UIImage * image = [[UIImage alloc] imageWithName:@"bart.jpg"];
cell = ... dequeue cell in UITableView data source (UITableViewController ...)
cell.text = @"bart";
cell.image = image;
要调整图像大小以适应单元格大小,需要做什么?
我见过这样的东西:
UIImageView * iview = [[UIImageView alloc] initWithImage:image];
iview.frame = CGRectMake(...); // or something similar
[cell.contentView addSubview:iview]
上面将添加图像到单元格,我可以计算大小以适合它,但是:
-
我不确定是否有更好的
对了,是不是太贵了
添加
UIImageView
只是为了调整
细胞图像
?
-
现在我的标签(
cell.text
)需要
随着图像的模糊而移动,
我看到了一个解决方案
将文本添加为标签:
例子:
UILabel * text = [[UILable alloc] init];
text.text = @"bart";
[cell.contentView addSubview:iview];
[cell.contentView addSubview:label];
// not sure if this will position the text next to the label
// edited original example had [cell addSubview:label], maybe that's the problem
有人能指点我正确的方向吗?
编辑
DoH
[cell.contentview addSubview:view]
不
[cell addSubview:view]
也许我应该看看这个:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = ...;
CGRect frame = cell.contentView.bounds;
UILabel *myLabel = [[UILabel alloc] initWithFrame:frame];
myLabel.text = ...;
[cell.contentView addSubview:myLabel];
[myLabel release];
}