[英]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:只要您的标签在 tableViewCell 中被正确约束,您就可以简单地设置:
label.adjustsFontSizeToFitWidth = true
Or if you're using the default UITableViewCell's textLabel, then in cellForRowAtIndexPath:或者,如果您使用默认的 UITableViewCell 的 textLabel,则在 cellForRowAtIndexPath 中:
cell.textLabel?.adjustsFontSizeToFitWidth = true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.