How to set Custom font to UILabel or Any Other UIView programmatically (if it is possible) i know how to do it in storyboard but not programmatically thank you
this what i did
Add this by drag and drop to your files on the left side of the project. Add your CUSTOM fonts to the info. plist file. Make sure that you've linked all custom fonts you need: "Build Phases" -> "Copy Bundle Resources" -> "+" add your font.
To change the font or the size of a UILabel in a Storyboard or . XIB file, open it in the interface builder. Select the label and then open up the Attribute Inspector (CMD + Option + 5). Select the button on the font box and then you can change your text size or font.
You can try
lbl.font = UIFont(name:"FontAwesome",size:15)
the name should be the font name as it is when you install it . not as the file name in your case was Noto Kufi Arabic instead of NotoKufiArabicRegular
click the font and open it with Font Book , then install it after that specify exactly the name shown in the parameter in the line above
import Foundation
import UIKit
extension UIFont {
public enum OpenSansType: String {
case extraboldItalic = "-ExtraboldItalic"
case semiboldItalic = "-SemiboldItalic"
case semibold = "-Semibold"
case regular = ""
case lightItalic = "Light-Italic"
case light = "-Light"
case italic = "-Italic"
case extraBold = "-Extrabold"
case boldItalic = "-BoldItalic"
case bold = "-Bold"
}
static func OpenSans(_ type: OpenSansType = .regular, size: CGFloat = UIFont.systemFontSize) -> UIFont {
return UIFont(name: "OpenSans\(type.rawValue)", size: size)!
}
var isBold: Bool {
return fontDescriptor.symbolicTraits.contains(.traitBold)
}
var isItalic: Bool {
return fontDescriptor.symbolicTraits.contains(.traitItalic)
}
}
Use:
self.numberLabel.font = UIFont.OpenSans(.bold, size: 20)
If the previous answer doesn't help, you didn't configure all links correctly at xCode for sure!
More information you can get here: Medium.com
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With