gpt4 book ai didi

iphone - UIView 子类 initWithFrame 没有被调用?

转载 作者:行者123 更新时间:2023-12-03 18:33:21 25 4
gpt4 key购买 nike

我有一个自定义 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];
}

最佳答案

从 Nib 加载的东西是用-(id)initWithCoder:(NSCoder*)coder初始化的

关于iphone - UIView 子类 initWithFrame 没有被调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3425598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com