मेरे पास एक कस्टम UIView उपclass है। आईबी में, मैंने एक "प्लेसहोल्डर" UIView निर्दिष्ट किया है और कक्षा को मेरे वर्ग के नाम पर सेट किया है। DrawRect विधि का मेरा ओवरराइड काम कर रहा है, और पृष्ठभूमि ठीक से रंग दे रही है, लेकिन initWithFrame फायरिंग नहीं है। क्यूं कर?UIView Subclass 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];
}
क्या आप वह कोड दिखा सकते हैं जहां आप कस्टम व्यू बनाते हैं? क्या आप कॉल कर रहे हैं: \t UIView * fred = [[UIView alloc] initWithFrame: myFrame]; – joelm