I have a custom View class built which subclasses UIView.
This view is loaded through a nib file in the ViewController via:
[[NSBundle main] loadNibNamed:@"MyCustomView" owner:self options:nil];
Inside MyCustomView.h (which correctly hooked up in IB as the Main Views class) I have some subview properties linked:
@interface MyCustomView : UIView <UITextFieldDelegate> {
....
@public
UIView *backgroundLayer; // a subview of the Main View inside the nib
....
}
@property (nonatomic, retain) IBOutlet UIView *backgroundLayer;
This outlet is properly connected within Interface Builder.
Inside MyCustomView.m I have the following implementation:
#import <quartzcore/QuartzCore.h>
@implementation MyCustomView
@synthesize backgroundLayer;
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
....
self.backgroundLayer.layer.cornerRadius = 12.0f;
self.backgroundLayer.layer.borderColor = [UIColor lightGrayColor].CGColor;
self.backgroundLayer.layer.maskToBounds = YES;
....
}
NONE of those backgroundLayer.layer settings are being applied. When I run in simulator the custom view appears exactly how it appears in the NIB without any of those mods? What am I missing? Am I making the calls in the incorrect place?
The correct answer to this issue was to use the method :
-(void)awakeFromNib {
......
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With