Ho una sottoclasse UIView personalizzata. In IB, ho specificato un UIView "segnaposto" e impostato la classe sul nome della mia classe. Il mio metodo override del metodo drawRect funziona e lo sfondo si colora correttamente, ma initWithFrame non si attiva. Perché?Sottoclasse UIView initWithFrame non viene chiamato?
- (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];
}
puoi mostrare il codice dove hai creato la vista personalizzata? Stai chiamando: \t UIView * fred = [[allocazione UIView] initWithFrame: myFrame]; – joelm