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

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

    I am using Swift, XCode 6.4. So this is what I did

    import Foundation
    import UIKit
    
        @IBDesignable class ExUILabel: UILabel {
    
            @IBInspectable var fontName: String = "Default-Font" {
                didSet {
                    self.font = UIFont(name: fontName, size:self.font.pointSize)
                }
            }
    
            override func layoutSubviews() {
                super.layoutSubviews()
                self.font = UIFont(name: fontName, size:self.font.pointSize)
            }
        }
    
    1. Goto Designer -> Identity Inspector -> Set the class to ExUILabel

    2. Then go to Attribute inspector in designer and set the font name.

提交回复
热议问题