开发者

Why are my UIView layer properties not being set when called within initWIthCoder:(NSCoder *)aDecoder?

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 withi开发者_如何转开发n 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 {
    ......
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜