0

所以我想知道是否可以在单元格的 detailTextLabel 中显示一个小图像?(我从 URL 获取图像)我尝试过:

NSString *thumbs = [NSString stringWithFormat:@"%@", TableText3];
cell.detailTextLabel.text = thumbs;

这显然是行不通的。我也尝试过:

UIImage *thumbs = [UIImage imageWithData:[NSData dataWithContentsOfURL:
                                          [NSURL URLWithString:TableText3]]];
cell.detailTextLabel.text = thumbs;

这也(显然)不起作用,因为我将图像传递给字符串参数。

令人惊讶的是,我在 WWW 上没有找到任何东西。(搜索参数是:“图像详细文本标签”或图片或只是文本标签和图像以及各种变体)

4

3 回答 3

2

您不能将其直接放入标签中,因为标签仅显示文本。但是你可以使用 UITableViewCell 的 imageView 属性。

cell.imageView = [[UIImageView alloc] initWithImage: thumbs];

https://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html

于 2012-03-05T22:21:36.300 回答
1

与其将图像放在 imageView 属性中,不如创建一个 UIImageView 并将其放置在 accessoryView 属性中:

UIImage     * thumbs;
UIImageView * thumbsView;
CGFloat       width;

thumbs             = [UIImage imageWithData:[NSData dataWithContentsOfURL:
                              [NSURL URLWithString:TableText3]]];
thumbsView         = [[[UIImageView alloc] initWithImage:thumbs] autorelease];
width              = (cell.frame.size.height * thumbs.size.width) / thumbs.size.height;
thumbsView.frame   = CGRectMake(0, 0, width, cell.frame.size.height);
cell.accessoryView = thumbsView;

这将调整图像大小以适合单元格并将其放置在 textLabel 和 detailTextLabel 的右侧。

于 2012-03-05T22:54:45.377 回答
1

更好的方法是不依赖内置的 UITableViewCell 类型并创建自己的单元格框架,并将所有标签、视图、图像添加到单元格内所需的位置。然后您可以返回表格视图的单元格。

于 2012-03-05T23:46:06.113 回答