how to change font size of date picker view and picker view in iOS Objective C

后端 未结 3 1615
不知归路
不知归路 2021-01-27 12:26

I want to change font size of date picker and picker view. is this possible ? if is it? then how it done.

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-27 12:50

    Actually you can update the font size using method swizzling. This is how I change the font

    #import "UILabel+Extra.h"
    
    @implementation UILabel (Extra)
    
    -(void)layoutSubviews{
        [super layoutSubviews];
    
        NSArray *arrayFont = [self.font.fontName componentsSeparatedByString:@"-"];
        NSArray *arrayRobotoStyleName = [UIFont fontNamesForFamilyName:@"Roboto"];
        __block NSString *style;
        if(arrayFont.count >= 2){
            [arrayRobotoStyleName enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger index, BOOL * _Nonnull stop){
                NSString *styleName = [arrayFont lastObject];
                if ([obj containsString:styleName]){
                    style = styleName;
                    *stop = TRUE;
                }
                else if (index == ([arrayRobotoStyleName count] - 1)){
                    style = @"Regular";
                    *stop = TRUE;
                }
            }];
        }
        else
            style = @"Regular";
    
        if (!style) {
            style = @"Regular";
        }
        self.font = [UIFont fontWithName:[NSString stringWithFormat:@"Roboto-%@",style] size:self.font.pointSize];
    }
    
    -(void)setAppearanceFont:(UIFont *)font{
        if (font)
            [self setFont:font];
    }
    
    -(UIFont *)appearanceFont{
        return self.font;
    }
    

提交回复
热议问题