当我添加 rightAnchor 约束时,constant= 20 不适用。在leftAnchor就可以了
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(collectionView)
collectionView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([collectionView.leftAnchor.constraint(equalTo: leftAnchor, constant: 20),
collectionView.topAnchor.constraint(equalTo: self.topAnchor),
collectionView.rightAnchor.constraint(equalTo: rightAnchor, constant: 20),
collectionView.heightAnchor.constraint(equalTo: self.heightAnchor)])
}
有人能帮我吗?
我有一种强烈的感觉,这就是你想要在那里做的事情rightAnchor
.
collectionView.rightAnchor.constraint(equalTo: rightAnchor, constant: -20)
如果您想从右侧或底部填充,则应使用负值。
经验法则:任何东西剩下的或上面的都是负面的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)