How do I apply UIAppearance Proxy properties to UILabel?

后端 未结 4 569
忘了有多久
忘了有多久 2020-11-27 20:34

I have been getting unreliable results while trying to apply UIAppearance proxy styles to the UILabel class proxy. For example, the following works as I would expect:

<
4条回答
  •  萌比男神i
    2020-11-27 21:17

    I have subclassed UILabel

    @interface SmallLabel : UILabel
    
    @end
    
    @implementation SmallLabel
    
    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
        }
        return self;
    }
    
    @end
    

    Then I use appearanceWhenContainedIn:

    UIFont *smallFont = [UIFont fontWithName:@"Arial" size:15];
    [[SmallLabel appearanceWhenContainedIn:[UIView class], nil] setFont:smallFont];
    

    This works to use the desired font for all SmallLabels in my app. I just need to set the Custom Class to SmallLabel in the XCode Identity Inspector. It does not seem to work with labels create programmatically, only those in NIBs.

    After further testing this method does not always work reliably.

提交回复
热议问题