简体   繁体   English

如何使用自动布局动态更改字体大小?

[英]How to change the font size dynamically using autolayout?

我想使用每个设备的代码动态更改每个设备的字体大小。我知道可以使用大小类来做到这一点/但我不想使用大小类。

@property int fontSize;

+(NSString *)getDeviceModel
{
    //Device Model
    NSString *phoneModel = [[UIDevice currentDevice] model];
    return phoneModel;
}

- (void)setLabelFontSize {
    NSString *hardware = [self getDeviceModel];
    if ([hardware isEqualToString:@"iPhone5,1"]) {
        self.fontSize = 10.0
    }else if ([hardware isEqualToString:@"iPhone6,1"]) {
        self.fontSize = 14.0
    }
    [_timeLabel setFont:[UIFont systemFontOfSize:self.fontSize]];
}

//I only list two device models, you can get other models through the Internet. //我只列出了两种设备型号,您可以通过Internet获得其他型号。

为uilabel提供宽高比约束,它将自动处理字体大小。

You may change font size base on size classes . 您可以根据大小类更改字体大小。 Below link will help you regarding this. 以下链接将帮助您解决此问题。 Font size using size class . 使用size类的字体大小 Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM