【发布时间】:2019-08-08 02:39:16
【问题描述】:
我有一个自定义视图,我想添加一个图像,使其底部锚点位于视图的 3/4。在情节提要中,我只需使用第一项 imgview.bottom、第二项 view.bottom、常量 0 和乘数 0.75 设置一个约束
在我尝试过的代码中:
let imgview = UIImageView(image: img)
imgview.translatesAutoresizingMaskIntoConstraints = false
addSubview(imgview)
NSLayoutConstraint.activate([
imgview.widthAnchor.constraint(equalTo: widthAnchor, multiplier: 0.4),
imgview.heightAnchor.constraint(equalTo: heightAnchor, multiplier: 0.4),
imgview.centerXAnchor.constraint(equalTo: centerXAnchor),
imgview.bottomAnchor.constraint(equalToSystemSpacingBelow: bottomAnchor, multiplier: 0.75)
])
但图像的底部甚至低于视图的底部。
如果我使用bottomAnchor.constraint(equalToSystemSpacingBelow: imgview.bottomAnchor, multiplier: 0.75)
它高于它,但仍然太低。我该怎么做?
【问题讨论】:
-
imgview的contentMode是什么?你可能需要做imgview.clipsToBounds = true
标签: swift