Search code examples
iosswiftuistoryboarduicontrol

Storyboard access UIControl property through global value


I have an iPhone app with a number of view controllers. Their respective UI is setup in the main storyboard file. For consistency, I have defined some global values for textfield heights, font sizes, button heights etc. that will be used by many controls. The current way of setting up these controls is by initialising them in the storyboard and then in the respective view controller, within viewDidAppear, the global values for heights, fonts and the like are accessed and assigned as the remaining properties of these controls.

But this process is fragmented and prone to error. Is there a better way of doing this? Is it possible to have access to global values, defined in swift files, within the storyboard? For instance, could the font of a textfield pointed to by the Attributes Inspector be actually referencing a global value?

Thanks


Solution

  • There is no way to set what you want , if you have a pre-defined height/Font , then set it directly in attributes inspector , if you want to configure for different devices you can try with size classes

    Or

    Create sub classes of the elements you want ( UITextField / UIIButton ) , and assign them to class name in IB