我在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()
}
}
答案 0 :(得分:0)
我遇到过类似的问题。您是否尝试过实现viewDidLayoutSubviews()?我想在这里你可以调整大小。只记得调用super.viewDidLayoutSubviews()