我在Swift中得到了这段代码
let image: UIImageView = {
let v = UIImageView()
v.image = #imageLiteral(resourceName: "st")
v.contentMode = .scaleAspectFit
v.frame = CGRect(x:0,y:0,width:100,height:100)
v.translatesAutoresizingMaskIntoConstraints = false
return v
}()
image.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
image.topAnchor.constraint(equalTo: view.centerYAnchor,constant:-170).isActive = true我的目标是拥有一个宽度为100、高度为100的UIImageView,其中包含一个具有相同度量的图像。但我的图像绝对比100px大。即使我将frame更改为10px,图像的大小也不会改变。
发布于 2017-07-13 03:44:12
你试过这个吗?
image.widthAnchor.constraint(equalToConstant: 100.0).isActive = true
image.heightAnchor.constraint(equalToConstant: 100.0).isActive = true或者我误解了你的问题..。
https://stackoverflow.com/questions/45065296
复制相似问题