简体   繁体   中英

Unable to get the height of a UILabel with numberOfLines = 0

When I set a text to my label and check myLabel.frame.size.height I get always the same value, as if being always a single line, even if the text I set takes multiple lines... How could I get the "final" height?

Thanks

Try it inside your View Controller's viewDidLayoutSubviews function:

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    print(myLabel.frame.size.height)
}

Your label won't have it's final size until then.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM