Mam niestandardową podklasę UIView. W IB podałem UIView "placeholder" i ustawiłem klasę na moją nazwę klasy. Moje nadpisanie metody drawRect działa, a tło jest poprawnie kolorowane, ale initWithFrame nie uruchamia się. Czemu?Podklasa UIView initWithFrame nie jest wywoływana?
- (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];
}
Czy możesz wyświetlić kod, w którym tworzysz niestandardowy widok? Czy dzwonisz: \t UIView * fred = [[przydziela UIView] initWithFrame: myFrame]; – joelm