let nameBox = UILabel(x: 0, y: 0, w: sideSize, h: sideSize*2/4)nameBox.text = skillNamenameBox.textAlignment = .CenternameBox.numberOfLines = 0nameBox.adjustsFontSizeToFitWidth = truenameBox.addBorderLeft(size: 1, color: UIColor.blackColor(
let nameBox = UILabel(x: 0, y: 0, w: sideSize, h: sideSize*2/4) nameBox.text = skillName nameBox.textAlignment = .Center nameBox.numberOfLines = 0 nameBox.adjustsFontSizeToFitWidth = true nameBox.addBorderLeft(size: 1, color: UIColor.blackColor()) nameBox.addBorderTop(size: 1, color: UIColor.blackColor()) nameBox.addBorderRight(size: 1, color: UIColor.blackColor()) container.addSubview(nameBox)
这是我的代码,其输出如下.
正如你所看到的那样,除了Communication& amp;伐木工人.为什么,我该如何解决?
看起来您需要将标签的lineBreakMode设置为.ByWordWrapping.另一个想法是你真的希望字体更小.也许这是由minimumScaleFactor属性阻止的.
从adjustsFontSizeToFitWidth的文档:
The default value for this property is false. If you change it to true, you should also set an appropriate minimum font size by modifying the minimumFontSize property.
这似乎是一个文档错误.不推荐使用minimumFontSize.