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

前端 未结 14 1263
隐瞒了意图╮
隐瞒了意图╮ 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: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

提交回复
热议问题