Custom Font Sizing in Xcode 6 Size Classes not working properly with Custom Fonts

前端 未结 14 1176
隐瞒了意图╮
隐瞒了意图╮ 2020-11-29 17:42

Xcode 6 has a new feature where fonts and font sizes in UILabel, UITextField, and UIButton can be s

相关标签:
14条回答
  • 2020-11-29 18:48

    Still no signed right answer. This code works fine for me. You must disable font size for size classes in interface builder first. In IB you can use custom font.

    - (void) traitCollectionDidChange: (UITraitCollection *) previousTraitCollection {
        [super traitCollectionDidChange: previousTraitCollection];
    
        if ((self.traitCollection.verticalSizeClass != previousTraitCollection.verticalSizeClass)
            || self.traitCollection.horizontalSizeClass != previousTraitCollection.horizontalSizeClass) {
    
             self.textField.font = [UIFont fontWithName:textField.font.fontName size:17.f];
    
        }
    }
    
    0 讨论(0)
  • 2020-11-29 18:49

    Fast fix:

    1) Set fonts as System for size classes

    Label attributes inspector

    2) Subclass UILabel and override "layoutSubviews" method like:

    - (void)layoutSubviews
    {
      [super layoutSubviews];
    
       // Implement font logic depending on screen size
        if ([self.font.fontName rangeOfString:@"bold" options:NSCaseInsensitiveSearch].location == NSNotFound) {
            NSLog(@"font is not bold");
            self.font = [UIFont fontWithName:@"Custom regular Font" size:self.font.pointSize];
        } else {
            NSLog(@"font is bold");
            self.font = [UIFont fontWithName:@"Custom bold Font" size:self.font.pointSize];
        }
    
    }
    

    By the way, it is a very convenient technique for iconic fonts

    0 讨论(0)
提交回复
热议问题