Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get .adjustsFontSizeToFitWidth to function properly

With this simple code, I was assuming that getting "Hello World!" to automatically shrink would work with bannerLabel.adjustsFontSizeToFitWidth but the end of the text is clipped with ... How do you get it to work properly?

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)!

    }
like image 244
Paul S. Avatar asked Mar 11 '15 20:03

Paul S.


1 Answers

titleLabel?.numberOfLines = 1 
titleLabel?.adjustsFontSizeToFitWidth = true
titleLabel?.minimumScaleFactor = 0.1
like image 67
buoge Avatar answered Oct 29 '22 03:10

buoge