简体   繁体   English

UITableviewCell中UIImageView的固有内容大小

[英]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.

相关问题 UIImageView 动态类型的固有内容大小行为 - UIImageView intrinsic content size behavior with Dynamic Type 如何让自动布局覆盖 UIImageView 的固有大小? - How can I get autolayout to override a UIImageView's intrinsic size? iOS 13 测试版中 WKWebView 的内在内容大小问题 - WKWebView's Intrinsic Content Size issue in iOS 13 beta 自动布局,灵活的容器-容器的固有内容大小 - Autolayout, flexible container - container's intrinsic content size 如何在 Swift 中设置自定义视图的内在内容大小? - How to set a custom view's intrinsic content size in Swift? UITableViewCell的UIImageView上的UIActivityIndi​​cator - UIActivityIndicator on UITableViewCell's UIImageView 以小于其内在大小的大小显示UIImageView - Show UIImageView at a size smaller than its intrinsic size 包装器不将其内在内容大小作为其子项与它们之间的约束之和 - Wrapper does not take it's Intrinsic Content Size as sum of it's children and constraints between them drawRect是否会更改内部内容的大小? - Does drawRect change intrinsic content size? 仅包含文本的按钮的固有内容大小 - Intrinsic content size of button with text only
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM