[英]UIImageView's intrinsic content size in UITableviewCell
I have a Tableview Cell with an Imageview. 我有一个带Imageview的Tableview单元。 I want to show Image as full-size ie the height of image is same as actual image. 我想以全尺寸显示图像,即图像的高度与实际图像相同。
The Tableview cell height should be same as Actual image height. Tableview单元格的高度应与实际图像高度相同。
How can I achieve this? 我该如何实现?
Thank you, 谢谢,
I assume you have an array having image names. 我假设您有一个具有图像名称的数组。
Use The following method 使用以下方法
for Objective-C 对于Objective-C
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
UIImage *image = [UIImage imageNamed:[self.arrImages objectAtIndex:indexPath.row]];
if (image == nil){
return 36; //return any static value
} else {
return image.size.height;
}
}
for Swift 对于斯威夫特
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let image = UIImage(named: arrImages[indexPath.row])
image?.size.height
if image == nil {
return 36 //return any static value
} else {
return (image?.size.height)!
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.