Last Updated: February 25, 2016
·
446
· trustyfrog

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.