简体   繁体   中英

How to get tableview header to adjust font to fit width

I am using the following line of code to adjust my tableview header font. [[UILabel appearanceWhenContainedIn:[UITableViewHeaderFooterView class], nil] setFont:[UIFont boldSystemFontOfSize:16]];

How can I adjust this font to fit width? The line below does not work? [UILabel setAdjustsFontSizeToFitWidth:YES];

You have several solutions to this

  1. Use Auto-Resizing, which will take some time if you are not familiar with

  2. Use below method on NSString object to find the size of resultant string with specified size and find the appropriate font size, like

[@"CheckString" sizeWithFont:[UIFont boldSystemFontOfSize:16]] ;

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