Search code examples
swiftlabeluilabelsizefont-size

Label does not adjust Font Size to fit width


enter image description here

This is how my app looks although I entered this code inside my ViewController class:

@IBOutlet var label: UILabel!

override func viewDidLoad() {
    super.viewDidLoad()

    label.text = "Hello World"
    label.adjustsFontSizeToFitWidth = true
    label.numberOfLines = 1
    label.minimumScaleFactor = 0.1
}

Solution

  • Your text data is not more than label width that's why label text font is same as already set. IF your text data is more then label width then it will adjust font according to the width.

    Please check with label text: "This is the demo to test label text is adjustable or not. You need to test it with this demo data"

    Your label font will adjust according to the width.