UILabel的minimumScaleFactor如何工作? [英] How does a UILabel's minimumScaleFactor work?

查看:588
本文介绍了UILabel的minimumScaleFactor如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前使用过 minimumFontSize 但该功能现已弃用,我不太明白 minimumScaleFactor 的工作原理。

I have used minimumFontSize before but that function is now deprecated and i don't quite understand how minimumScaleFactor works.

我希望最大字体大小为10,最小字体大小为7.

I want the maximum font size to be 10 and the minimum to be 7.

我怎么能使用比例因子将重新调整大小缩小到字体大小7?

How can I achieve the re-size down to font size 7 with the scale factor?

UILabel 创建:

UILabel *label = [[UILabel alloc] init];
[label setTranslatesAutoresizingMaskIntoConstraints:NO];
label.text =  [labelName uppercaseString];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.font = [UIFont fontWithName:HELVETICA_FONT_STYLE_BOLD size:9.5];
label.backgroundColor = [UIColor clearColor];
label.minimumScaleFactor = .1f;

[label addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[label(WIDTH)]"
                                                              options:0
                                                              metrics:@{@"WIDTH" : [NSNumber numberWithFloat:buttonSize.width]}
                                                                views:NSDictionaryOfVariableBindings(label)]];

[contentView addSubview:label];


推荐答案

您需要设置 label.adjustsFontSizeToFitWidth = YES;

这篇关于UILabel的minimumScaleFactor如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆