Search code examples
iosiphoneswiftxcodexcode-storyboard

How to do app-wide / faster updates by UI element type, in Swift using Xcode ...?


Just curious - doing some maintenance on a swift app, bit time consuming, would love to know if there is a better recommended way, or faster way (?), to do mass updates for a UI element type, e.g. update all buttons, to have a certain property, e.g. say a color or width constraint...?


Solution

  • Color, yes, by using the button's appearance proxy, like

    UIButton.appearance().backgroundColor = UIColor.whateverColor()
    

    Width constraint, no. There are a couple other ways to do it, though.

    • If your regex skills are sharp, you can do a search & replace in all of the storyboards' and xibs' XML code to add a width constraint to each, but that'd be error-prone because some of them may already have width constraints.
    • You can subclass UIButton and give it a width constraint and set any other properties you wish, but you'd still have to search-and-replace all UIButtons in the appearance files with your custom class type.