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

前端 未结 14 1269
隐瞒了意图╮
隐瞒了意图╮ 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:42

    This (and other Xcode - Size Classes related) bug caused me some serious grief recently as I had to go through a huge storyboard file hacking things away.

    For anyone else in this position, I'd like to add something on top of @razor28's answer to ease the pain.

    In the header file of your custom subclass, use IBInspectable for your runtime attributes. This will make these attributes accessible from the "Attributes Inspector", visually right above the default position for font settings.

    Example use:

    @interface MyCustomLabel : UILabel
    
        @property (nonatomic) IBInspectable NSString *fontType;
        @property (nonatomic) IBInspectable CGFloat iphoneFontSize;
        @property (nonatomic) IBInspectable CGFloat ipadFontSize;
    
    @end
    

    This will very helpfully produce this output:

    enter image description here

    An added benefit is that now we don't have to add the runtime attributes manually for each label. This is the closest I could get to XCode's intended behaviour. Hopefully a proper fix is on its way with iOS 9 this summer.

提交回复
热议问题