E-M*_*add 8 iphone cocoa-touch
我有一个自定义的UIView子类.在IB中,我指定了一个"占位符"UIView并将该类设置为我的类名.我对drawRect方法的重写是有效的,并且背景正确着色,但是initWithFrame没有触发.为什么?
- (id)initWithFrame:(CGRect)frame {
NSLog(@"initWithFrame");
if ((self = [super initWithFrame:frame])) {
noteTextFont = [[UIFont boldSystemFontOfSize:12] retain];
}
return self;
}
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *backgroundColor = [UIColor blackColor];
[backgroundColor set];
CGContextFillRect(context, rect);
UIColor *labelColor = [UIColor lightGrayColor];
[labelColor set];
[notificationLabel drawInRect:CGRectMake(44, 18, rect.size.width-20, rect.size.height) withFont:noteTextFont lineBreakMode:UILineBreakModeTailTruncation];
[self setNeedsLayout];
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5513 次 |
最近记录: |