skå*_*fan 9 iphone cocoa-touch interface-builder uiview ios4
我有一个自定义的View类,它构建了UIView的子类.
此视图通过ViewController中的nib文件加载:
[[NSBundle main] loadNibNamed:@"MyCustomView" owner:self options:nil];
Run Code Online (Sandbox Code Playgroud)
在MyCustomView.h里面(它正确地连接在IB作为主视图类)我有一些链接的子视图属性:
@interface MyCustomView : UIView <UITextFieldDelegate> {
....
@public
UIView *backgroundLayer; // a subview of the Main View inside the nib
....
}
@property (nonatomic, retain) IBOutlet UIView *backgroundLayer;
Run Code Online (Sandbox Code Playgroud)
此插座在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;
....
}
Run Code Online (Sandbox Code Playgroud)
NONE这些backgroundLayer.layer设置被应用.当我在模拟器中运行时,自定义视图会出现在它没有任何这些模块的NIB中的显示方式吗?我错过了什么?我在错误的地方打电话了吗?
skå*_*fan 16
这个问题的正确答案是使用该方法:
-(void)awakeFromNib {
......
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2043 次 |
| 最近记录: |