iosswiftautolayoutsnapkit

how to set edge offset proportionally to size of superview height in SnapKit


Here is what I am trying to achieve with SnapKit, but it does not compile for obvious reasons.

contentView.snp.makeConstraints { (make) in
   make.top.equalTo(scrollView).offset(scrollView.snp.height * 0.2) //ERROR - Binary operator cannot be applied to type ConstraintItem and Double 
} 

Solution

  • Try:

    contentView.snp.makeConstraints { make in
        make.height.equalToSuperview().dividedBy(2)
        make.left.right.bottom.equalToSuperview()
    }