rightAnchor constraint did not apply when added programmatically - swift

后端 未结 2 1737
被撕碎了的回忆
被撕碎了的回忆 2021-01-23 11:40

When I Added rightAnchor constraint, constant= 20 did not apply. In leftAnchor is ok

override init(frame: CGRect) {
    super.init(frame: frame)

    addSubview         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-23 12:42

    I have a really strong feeling that this is what you wanted to do there for rightAnchor.

    collectionView.rightAnchor.constraint(equalTo: rightAnchor, constant: -20)

    If you want padding from the right or bottom you should use negative values.


    Rule of thumb: Whatever is left or upwards of something is negative.

提交回复
热议问题