调整单元格

时间:2017-05-31 17:00:26

标签: ios swift swift3

我在UIImageView内有一个UITableViewCell,根据所用iPhone的类型,我想调整UIImageView宽度。问题是当我尝试在awakeFromNib中设置宽度时,ImageView宽度保持不变,即NIB文件。继承我的代码。

override func awakeFromNib() {
    super.awakeFromNib()
    let screenSize: CGRect = UIScreen.main.bounds
    let screenHeight = screenSize.height
    if screenHeight == 568 {
        ProductImage.frame.size.width = 200
        self.layoutIfNeeded()
    }else if screenHeight == 667 {
        ProductImage.frame.size.width = 50
        self.layoutIfNeeded()
    }else if screenHeight == 736 {
        ProductImage.frame.size.width = 100
        self.layoutIfNeeded()

    }


}

1 个答案:

答案 0 :(得分:0)

我遇到过类似的问题。您是否尝试过实现viewDidLayoutSubviews()?我想在这里你可以调整大小。只记得调用super.viewDidLayoutSubviews()