0
這是我的課:的UIImageView忽略寬度/高度限制
class Some: UIView{
override init(frame: CGRect) {
super.init(frame: frame)
load()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
load()
}
private func load(){
let someImage = UIImageView()
someImage.translatesAutoresizingMaskIntoConstraints = false
someImage.image = UIImage(named: "Test")
self.addSubview(someImage)
someImage.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
someImage.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
someImage.widthAnchor.constraint(equalTo: self.widthAnchor, multiplier: 0.5)
someImage.heightAnchor.constraint(equalTo: self.heightAnchor, multiplier: 0.5)
}
}
這是結果:
(橙色是我的ViewController的背景)
爲什麼我的圖片忽略此行:
someImage.widthAnchor.constraint(equalTo: self.widthAnchor, multiplier: 0.5)
someImage.widthAnchor.constraint(equalTo: self.widthAnchor, multiplier: 0.5)
它在圖像中顯然具有乘數1.0。它實際上應該佔據屏幕的一半,在乘法器(0.5)中看到的高度和寬度都是如此。我究竟做錯了什麼?
I.Am.So.Stupid。::( –
總是伴隨着我:D – Raj