Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use prepeocessor macros in storyboard elements?

I want to use pre-defined macros in StoryBoard elements

For example: I have a 10 textfield in my app and if I want to change the size of all textfield through preprocessor macros then it will be easier and faster. In that case we only need to change that macro variable.

like image 661
Pratik Bhiyani Avatar asked May 13 '14 07:05

Pratik Bhiyani


1 Answers

So the core issue is the usage of shared constants for Interface Builder files.

Preprocessor macros can only be used in files that are run through the C preprocessor — essentially just your code. So you can't use macros to implement shared constants for IB files. Similarly you cannot use actual constants that you define in your code files.

What you can do, however, is to create a custom UITextField (or any UIView for that matter) subclass, set your constant values (or define any other custom behavior) in the subclass implementation, and then select this custom class name in Interface Builder's Identity Inspector -> Custom Class section for all of your text field elements.

like image 171
hasseg Avatar answered Oct 18 '22 16:10

hasseg