I have a custom button, subclassed from UIButton that is initialised as below (obviously all the button does is use a custom font).
@implementation HWButton
- (id)initWithCoder:(NSCoder *)decoder {
if (self = [super initWithCoder: decoder]) {
[self.titleLabel setFont:[UIFont fontWithName: @"eraserdust" size: self.titleLabel.font.pointSize]];
}
return self;
}
So far so good. But when I use the custom class in my nib and launch the app, the button initially displays for a split second as tiny with small text, then grows. So the outcome is what I want, but I don’t want to see the transition. Can anyone put me right?
Thanks.
JP
I haven’t see this problem but it sounds like the initial frame of the button is way to small. When a button loads from nib, it draws itself with the frame assigned in the nib. It only adjust itself for other factors after it is up and running.
Changing font size isn’t something that is normally done during initialization and it has a lot of side effects so the class may well ignore the sizeToFit until the button has completely initialized.
I think the simplest work around for you is to set the frame in IB to the frame it will have with the font you want to use. That way, you shouldn’t see the transition at all.
If the button doesn’t have to change size once drawn, I would recommend using an image instead of text. Just whip out a Gimped button and be done with it.