Ios 如何调整图像大小以适应UITableView单元格?
如何将Ios 如何调整图像大小以适应UITableView单元格?,ios,objective-c,uitableview,cocoa-touch,uikit,Ios,Objective C,Uitableview,Cocoa Touch,Uikit,如何将UIImage放入UITableView,UITableView单元格(?)的单元格中 在将子视图添加到单元格之前,是否有方法调整单元格.图像或UIImage的大小 我想保持默认的单元格大小(无论是什么,当你初始化为零矩形),并希望添加图标一样的图片到每个条目。图像略大于单元格大小(表行大小) 我认为代码是这样的(从我的头顶上看): 我需要做什么来调整图像大小以适应单元格大小? 我见过这样的情况: UIImageView * iview = [[UIImageView alloc] ini
UIImage
放入UITableView
,UITableView单元格(?)的单元格中
在将子视图添加到单元格
之前,是否有方法调整单元格.图像
或UIImage
的大小
我想保持默认的单元格大小(无论是什么,当你初始化为零矩形),并希望添加图标一样的图片到每个条目。图像略大于单元格大小(表行大小)
我认为代码是这样的(从我的头顶上看):
我需要做什么来调整图像大小以适应单元格大小?
我见过这样的情况:
UIImageView * iview = [[UIImageView alloc] initWithImage:image];
iview.frame = CGRectMake(...); // or something similar
[cell.contentView addSubview:iview]
上面的内容会将图像添加到单元格中,我可以计算出适合它的大小,但是:
我不确定是否有更好的办法
顺便问一下,这不是太多的开销吗
添加UIImageView
只需调整
cell.image
现在我的标签(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];
}
重新缩放UIImage*
时。您可以使用缩放来获得您正在使用的UIImage*
的正确比例,从而将其缩小 如果您可以访问apple devloper center,则会有一个关于缩放表格视图图像的视频。它更关注性能问题,并讨论了很多线程,但他确实展示了一些用于调整图像大小的示例代码
视频名称:“有效的iPhone应用程序开发-第2部分”约30分钟
- (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];
}