XIB Style Helper
Sometimes you need to apply styles to views in a XIB. Although you can subclass views or programmatically set values sometimes you just want a simple label to have a red background.
Create a subclass of NSObject:
@interface XibStyle : NSObject {
IBOutletCollection(UILabel) NSArray *redLabel;
}
@implementation XibStyle
- (void)awakeFromNib {
for (UILabel *label in redLabel) {
label.backgroundColor = [UIColor redColor];
}
}
Now, in the XIB drag an "Object" from the Object Library to the Objects. Set its class to XibStyle.
If you look at the object's Connection Inspector you will see a connection for redLabel. Drag the connection onto any labels you want to have a red background and away you go.
Written by Scott
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ios
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#