Reputation: 4079
i am subclassing a UILabel
to set a custom font so i can use it across header bars in my app. so i have created a HeaderLabel
class that inherit from UILabel
and i have added this code to set the font :
- (id)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if (self) {
self.font = [UIFont fontWithName:@"fbTypoPas-Black" size:34];
self.textColor = [UIColor whiteColor];
}
return self;
}
i am not holding any reference to theHeaderLabel
from IB
just setting the text i want.
it works well on IOS
7, IOS
6 and 5 not seem to be working
Upvotes: 1
Views: 1268
Reputation: 25144
Try it in -(void)awakeFromNib
, but don't forget to call [super awakeFromNib]
!
Upvotes: 1
Reputation: 3850
Try like that:
- (id)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if (self) {
dispatch_async(dispatch_get_main_queue(), ^{
self.font = [UIFont fontWithName:@"fbTypoPas-Black" size:34];
self.textColor = [UIColor whiteColor];
});
}
return self;
}
Upvotes: 2