I have a custom view which contains two UILabel. I want to customize their fonts before so I did that in initWithCoder method.
@implementation HomeTitleView
@synthesize ticketLabel;
@synthesize monthLabel;
- (id) initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
if (self) {
[monthLabel setFont:[UIFactory getFontForKey:@"home_month"]];
[ticketLabel setFont:[UIFactory getFontForKey:@"home_ticket"]];
}
return self;
}
@end
Unluckily, this did not work. Using a debugger, I found that monthLabel and ticketLabel are both nil. Anyone has idea how can I solve this? What callback or method I should implement so that I can access both of my labels?
You can’t do that. The views don’t exist yet. They are instantiated when the
loadViewmethod is called, which happens automatically when theviewproperty is first accessed. If you want to manipulate your views after they have loaded, the correct method to use isviewDidLoad.Edit: That’s assuming you are working with a
UIViewControllerclass. If you are working with aUIViewclass, you can useawakeFromNibordidAddSubview:.