【发布时间】:2016-12-12 18:37:12
【问题描述】:
我正在制作一个标签,并尝试将字体设置为“Avenir”,如下所示:
let usernameLabel: UILabel
usernameLabel = UILabel(frame: CGRect(x: 20, y: third * screenHeight + sixth * screenHeight, width: third * screenWidth, height: 30))
usernameLabel.text = "Username"
usernameLabel.font = UIFont(name: "Avenir", size: 30) // Where I set the font
usernameLabel.sizeToFit()
usernameLabel.textColor = UIColor.gray()
self.view.addSubview(usernameLabel)
但是我希望使用 usernameLabel.sizeToFit() 动态调整大小,但这没有效果,因为我必须在设置字体时设置大小,如果我尝试不使用大小选项,它会返回错误.
【问题讨论】:
-
试试 [usernameLabel setAdjustsFontSizeToFitWidth:YES];
标签: ios iphone swift fonts font-size