문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top