为什么在initWIthCoder:(NSCoder *)aDecoder中调用时,我的UIView图层属性未设置? [英] Why are my UIView layer properties not being set when called within initWIthCoder:(NSCoder *)aDecoder?
问题描述
我有一个自定义View类构建的子类UIView。
I have a custom View class built which subclasses UIView.
这个视图是通过ViewController中的nib文件加载的:
This view is loaded through a nib file in the ViewController via:
[[NSBundle main] loadNibNamed:@"MyCustomView" owner:self options:nil];
内部 MyCustomView.h (可正确连接到IB视图类)
我有一些子视图属性链接:
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;
此插座在Interface Builder中正确连接。
This outlet is properly connected within Interface Builder.
在 MyCustomView.m 中,我有以下实现:
#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 正在应用那些backgroundLayer.layer设置。当我在模拟器运行自定义视图出现完全如何出现在NIB没有任何这些MOD?我缺少什么?
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 {
......
}
这篇关于为什么在initWIthCoder:(NSCoder *)aDecoder中调用时,我的UIView图层属性未设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!