I have static UITableView
with Basic style cells, default 44 height. There is a label in each cell with Body text style. This way I'm getting Dynamic Type behaviour for free.
It works except if:
I managed to fix this with following hack
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(preferredContentSizeChanged)
name:UIContentSizeCategoryDidChangeNotification object:nil];
}
- (void)preferredContentSizeChanged
{
// adjust the layout of the cells
// for some reason text from labels are disappear
self.statusBarCell.textLabel.text = @"Status bar";
self.itemColorCell.textLabel.text = @"Color";
But I have another exactly the same UITableView
and this is not working. I tried outlets for cells and labels. I tried reloadData
and setNeedsLayout
methods.
Here is pictures. Labels are yellow and content view is blue:
I recently played with static tables and tried to add dynamic type to it. I got the same results as you - one even can see this vanishing label in Apple's own Contacts.app.
Even after changing my table from static to dynamic and implementing a small custom cell containing a UILabel (configured with font as UIFontTextStyleBody in the XIB) the table still didn't seem to update its contents when changing the preferred text size in system prefrences.
However: I accidentally got some results after doing the following: in the subclass for my custom cell I implemented prepareForReuse and re-initialize the label's font to the correct style:
- (void)prepareForReuse {
self.label.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
}
With the hack above my table cells adapt their fonts dynamically to changes in system preferences.
Hope that helps.
I changed table to a dynamic and implemented cellForRowAtIndexPath:
method to assign table label in code. This is not helped me.
Next I changed table view cell style from basic to custom. I had to add my own label and set up AutoLayout constraints in Storyboard. This is solved the issue. preferredContentSizeChanged
notification is no longed necessary.
In my cellForRowAtIndexPath
:
cell.label.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
I will file an Apple radar later. Looks like we can't use Dynamic Type with static tables.
Good luck and please implement Dynamic Type in your apps. It's worth it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With