我构建了一个自定义 View 类,它是 UIView 的子类。
该视图通过 ViewController 中的 nib 文件加载:
[[NSBundle main] loadNibNamed:@"MyCustomView" owner:self options:nil];
Inside MyCustomView.h(在 IB 中正确连接为 Main Views 类)
我链接了一些子视图属性:
@interface MyCustomView : UIView <UITextFieldDelegate> {
....
@public
UIView *backgroundLayer; // a subview of the Main View inside the nib
....
}
@property (nonatomic, retain) IBOutlet UIView *backgroundLayer;
该插座已在 Interface Builder 中正确连接。
Inside 我的自定义视图.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 中的显示方式完全一样,没有任何这些 mods?我缺少什么?我是否在错误的地方拨打了电话?
这个问题的正确答案是使用以下方法:
-(void)awakeFromNib {
......
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)