Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Some sort of "global" for IBDesignables?

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 scenes.

Say you want to change the value 0.1 to 0.975.

You have to change it individually everywhere.

Is there some way to make a sort of "global value", using @IBInspectable and/or constraints?

So that you can change them all at once, and see the results all at once in storyboard.

(Of course, at run-time you could propagate these in code. But it's better to see it on storyboard.)


Note for example that Wain's solution below works perfectly: you can set the value once, and affect everywhere in the app. But unfortunately it only does that at run time, you don't see it on storyboard.

like image 533
Fattie Avatar asked Jun 23 '16 19:06

Fattie


1 Answers

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:

enter image description here

like image 97
Wain Avatar answered Sep 19 '22 09:09

Wain