Вы можете достичь этого, создав подкласс UILabel, и следующий пример может вам помочь.
class CustomLabel: UILabel
{
@IBInspectable var textFont:Int = 0
required init?(coder aDecoder: NSCoder)
{
super.init(coder: aDecoder)
initializeLabel()
}
override init(frame: CGRect) {
super.init(frame: frame)
initializeLabel()
}
func initializeLabel()
{
self.font = FontType.getFont(rawValue: textFont)
}
}
enum FontType: Int
{
case Default = 0, Small, Large
var fount: UIFont
{
switch self
{
case .Default:
return UIFont.systemFont(ofSize: 40)
case .Small:
return UIFont.systemFont(ofSize: 80)
case .Large:
return UIFont.systemFont(ofSize: 100)
}
}
static func getFont(rawValue: Int) -> UIFont
{
if let fontType = FontType(rawValue: rawValue)
{
return fontType.fount
}
return FontType.Default.fount
}
}
Кроме того, вам нужно будет установить свойство в XIB / Storyboard:


Надеюсь, это вам поможет.