如何让.adjustsFontSizeToFitWidth正常运行

时间:2015-03-11 20:06:47

标签: swift xcode6 uilabel

使用这个简单的代码,我假设让"Hello World!"自动缩小将与bannerLabel.adjustsFontSizeToFitWidth一起使用,但文本的末尾会被...剪切。如何让它工作?正常?

import UIKit

class ViewController: UIViewController, UIGestureRecognizerDelegate {

    @IBOutlet weak var bannerLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()

        bannerLabel.adjustsFontSizeToFitWidth = true
        bannerLabel.numberOfLines = 1
        bannerLabel.text = "Hello World!"
        bannerLabel.font = UIFont(name: bannerLabel.font.fontName, size: 150)!

    }

1 个答案:

答案 0 :(得分:6)

titleLabel?.numberOfLines = 1 

titleLabel?.adjustsFontSizeToFitWidth = true

titleLabel?minimumScaleFactor = 0.1