Some sort of “global” for IBDesignables?

前端 未结 3 1022
走了就别回头了
走了就别回头了 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:07

    I haven't tried it, and this is just typed in here so excuse typos, but I would consider creating an extension on NSLayoutConstraint, something along the lines of:

    let constants = [
        "bannerHeight" : CGFloat(50)
    ]
    
    extension NSLayoutConstraint {
    func setCommonConstant(name: String) {
        self.constant = constants[name]!
    }
    }
    

    and then using the user defined runtime attributes in Xcode so specify the name to use:

    commonConstant, type String, value name
    

    So, like this, on each Constraint anywhere in the storyboard:

提交回复
热议问题