I’m updating my application to support dynamic type in iOS 7. It was pretty easy to make the text by adjusting its size depending on the system parameters, but since I use it in the context of UITableView and cells with several UILabels in them, the text size is not the only one what should i worry about. If the text grows, the cell height should also be if the text is compressed, therefore the cell height.
In addition, if it becomes smaller, it should have a smaller distance between the elements compared to its largest type (as with a small size, the gaps between them will be gigantic). A.
How to change more complex layout problems, for example, when a user changes his size of a dynamic type?
Right now, I'm doing something really ugly that barely works. I look at the height of one of my shortcuts and scale my constants with its size. But this is very inaccurate, because, say, 110% of the height of the UILabel with the current size of the text used as an addition between the elements will not necessarily work everywhere.
So here is what I am doing in this example:
CGRect articleTitleRect = [article.title boundingRectWithSize:CGSizeMake(CGRectGetWidth(self.contentView.bounds) - 29, MAXFLOAT) options:NSStringDrawingUsesFontLeading attributes:@{ NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline] } context:nil]; self.urlConstant.constant = articleTitleRect.size.height / 5; self.previewConstant.constant = articleTitleRect.size.height / 5;
(Basically, figure out what the height of the label is, and then use the percentage of it to infer the interval. Again, it’s very inaccurate and doesn’t work well everywhere.)
Another thing that I considered was checking that the current preferredFontForTextStyle: is equal to the size of the point, and for specific values - hard code for adjusting / spacing the interface. This works a little better, but it still does not seem optimal for what Apple had in mind, because it is not very dynamic (it breaks if they add a different type of size, for example), and you almost sniff for values, t give you right off the bat (which makes it seem hacked).
So what do apps like Tweetbot 3 (which now use Dynamic Type to set their UITableViewCell elements) do to make their user interface so well-executed for different types of dynamic type? What is the best way to do this? There honestly it seems that there are no textbooks on this topic.