Custom Font Sizing in Xcode 6 Size Classes not working properly with Custom Fonts

前端 未结 14 1272
隐瞒了意图╮
隐瞒了意图╮ 2020-11-29 17:42

Xcode 6 has a new feature where fonts and font sizes in UILabel, UITextField, and UIButton can be s

14条回答
  •  温柔的废话
    2020-11-29 18:37

    I've come up with even faster fix (I assume you always use your one custom font).

    Create a category for UILabel and include in files using buggy storyboard with size classes and dedicated font setting for various classes:

    @implementation UILabel (FontFixForSizeClassesAppleBug)
    
    - (void)layoutSubviews
    {
        [super layoutSubviews];
        if([[UIFont systemFontOfSize:10].familyName isEqualToString:self.font.familyName]) {
            //workaround for interface builder size classes bug which ignores custom font if various classes defined for label: http://stackoverflow.com/questions/26166737/custom-font-sizing-in-xcode6-size-classes-not-working-properly-w-custom-fonts
            self.font = [UIFont fontWithName:@"YOUR_CUSTOM_FONT_NAME" size:self.font.pointSize];
        }
    }
    
    @end
    

    Just use your custom fonts in storyboard. When buggy interpreter will use system font instead your own this category will switch it to your custom font.

提交回复
热议问题