Ortwin Gentz Ortwin Gentz - 1 year ago 69
iOS Question

Limit supported Dynamic Type font sizes

I want to support Dynamic Type but only to a certain limit, similar to the Settings.app where standard

s can grow up to
but not larger.

Is there an easy way to accomplish this with standard UITableViewCell styles?

Answer Source

I solved the issue in my custom UITableViewCell subclass:

CGFloat const ftMaximumDynamicFontSize = 23;

@implementation MyTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
        [self adjustFonts];
    return self;

- (void)awakeFromNib {
    [super awakeFromNib];
    [self adjustFonts];

- (void)adjustFonts {
    UIFont *textFont = self.textLabel.font;
    self.textLabel.font = [UIFont fontWithName:textFont.fontName size:MIN(textFont.pointSize, ftMaximumDynamicFontSize)];

    UIFont *detailFont = self.detailTextLabel.font;
    self.detailTextLabel.font = [UIFont fontWithName:detailFont.fontName size:MIN(detailFont.pointSize, ftMaximumDynamicFontSize)];

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download