Question

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

enter image description here

Was it helpful?

Solution

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;
}

OTHER TIPS

Try it in -(void)awakeFromNib, but don't forget to call [super awakeFromNib] !

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top