简体   繁体   中英

How do I auto adjust the font size of a cells content to fit the tableview width?

I have a table view that shows the user what trips they have logged in. Except if the trip name is too long and doesn't fit within the table views width, it doesn't fully show. I would hope it's possible to simply resize the font so that it can fit within the table view, similar to the "Adjust to Fit" option that text fields have. Thanks!

As long as your label is properly constrained within the tableViewCell, you can simply set:

label.adjustsFontSizeToFitWidth = true

Or if you're using the default UITableViewCell's textLabel, then in cellForRowAtIndexPath:

cell.textLabel?.adjustsFontSizeToFitWidth = true

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