How do I make UITableViewCell's ImageView a fixed size even when the image is smaller

后端 未结 16 2508
不思量自难忘°
不思量自难忘° 2020-11-27 10:27

I have a bunch of images I am using for cell\'s image views, they are all no bigger than 50x50. e.g. 40x50, 50x32, 20x37 .....

When I load the table view, the tex

16条回答
  •  暖寄归人
    2020-11-27 11:01

    The solution we ended up with is similar to many of the others. But to get the correct position of the separator we had to set it before calling super.layoutSubviews(). Simplified example:

    class ImageTableViewCell: UITableViewCell {
    
        override func layoutSubviews() {
            separatorInset.left = 70
            super.layoutSubviews()
    
            imageView?.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
            textLabel?.frame = CGRect(x: 70, y: 0, width: 200, height: 50)
        }
    
    }
    

提交回复
热议问题