Tomáš Chylý
Tomáš Chylý

Reputation: 342

Xcode 5 wrong font size on UITextField after editing

I have UITextFields with custom font and size. Everything worked fine till I changed to Xcode 5 to fix all the changes with new iOS/Xcode. Now when I check my UITextFields they have the right font on placeholder and while editing, but when I stop editing the font size gets bigger. So why now with Xcode 5 it doesn't work?

Screenshots: link

Code to set font hasn't changed:

[_eventName setFont:[UIFont fontWithName:APP_FONT_FUTURASTD_LIGHT size:16]];

Upvotes: 3

Views: 903

Answers (4)

skagedal
skagedal

Reputation: 2411

I had this problem, and just like described by chrisoneiota the problem is that the UITextField uses a UILabel for some situations. I solved it also by overriding the UITextField, but instead of implementing drawInRect: I do:

- (void)addSubview:(UIView *)view {
    if ([view isKindOfClass:[UILabel class]]) {
        UILabel *label = (UILabel *)view;
        label.font = self.font;
    }
    [super addSubview:view];
}

This appears to work well.

Upvotes: 0

chrisoneiota
chrisoneiota

Reputation: 452

I too had an issue when inserting rows in a table - the text field in the table cell would use the UILabel proxy font, not the font set on its font property. Scrolling off the screen and back on would then show the correct font.

The only way I was able to fix this was to override UITextField, add a custom drawRect - in here I had to set self.font to nil, then reset self.font to the value I desired.

Chris

Upvotes: 0

Jamie Forrest
Jamie Forrest

Reputation: 11113

Have you made changes to the appearance proxy for UILabels? I'm having a similar issue where it appears as if UITextField's text is rendered as a UILabel after editing is completed. Overriding my appearance proxy settings on UILabel fixed this issue for me.

Upvotes: 2

Jordan Montel
Jordan Montel

Reputation: 8247

Now you need to use sizeWithAttributes: instead, which now takes an NSDictionary. Pass in the pair with key UITextAttributeFont and your font object like this :

[_eventName.text sizeWithAttributes:@{NSFontAttributeName:[UIFont fontWithName:APP_FONT_FUTURASTD_LIGHT size:16]}]

Upvotes: 0

Related Questions