Some sort of “global” for IBDesignables?

前端 未结 3 1060
走了就别回头了
走了就别回头了 2021-01-12 08:34

In storyboard have a UIView, with a constraint for example \"0.1\" proportional height.

Imagine you have a similar constraint \"0.1\", on views in many different sce

3条回答
  •  别那么骄傲
    2021-01-12 09:15

    I tried to find something similar when i started developing using Storyboard and Interface Builder. Unfortunately, xCode is not so scalable and code centralization using Interface Builder can't be implemented easily as can be done in Android development for example.

    You could try something like this, use custom @IBDesignable attribute in UIView extension and change constraints values or adding constraint at runtime (but i don't know if it will affect Interface Builder too):

    extension UIView {
        @IBInspectable var insertTopConstraint: Bool {
            set {
                // suppose 10 is your fixed value
                addConstraint(NSLayoutConstraint(item: self, attribute: .Top, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1, constant: 10))
                updateConstraintsIfNeeded() // could be useful..
            }
            get {
                return true
            }
        }
    }
    

    It could be a starting point. Hope it helps

提交回复
热议问题