ios - UILabel minimumScaleFactor 是如何工作的?

我以前使用过 minimumFontSize,但该功能现在已弃用,我不太了解 minimumScaleFactor 的工作原理。

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

如何使用比例因子将字体大小调整为 7?

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;

https://stackoverflow.com/questions/14650990/

相关文章:

ios - 如何在 xcode 中以编程方式向按钮添加操作

objective-c - 如何从 NSSet 返回 NSMutableArray

objective-c - 如何获取 NSString 的前三个字符?

iphone - Xcode 4.5 Storyboard 'Exit'

iphone - 如何将 UIImage 保存到文件中?

ios - 获取 UITableView 的 Selected 索引

ios - AVAudioPlayer 在 Debug模式下抛出断点

iphone - 我什么时候应该在 -(void)viewDidUnload 而不是 -deallo

ios - 错误 : CUICatalog: Invalid asset name supplied

objective-c - 声明的属性是否需要相应的实例变量?