0
我在UITableViewCell
内部有一个UIImageView
,根据所用iPhone的类型,我想调整UIImageView
的宽度。问题是当我尝试将宽度设置为awakeFromNib
时,ImageView
的宽度保持相同,即在NIB
文件中。继承人我的代码。调整单元格中的UIImage宽度
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()
}
}
你有没有看过使用自动布局? – Stefan
是的,它没有做我需要的。我怎样才能使代码上面的工作 – ahmed
你想做什么,请解释一下,如果你想做usign Code,将代码从'awkeNib'移到'drawRect' – Dhiru