The following abbr
Q: Adding a new f
The present invent
[Cite as State v.
It’s that time of
The use of dental
Heterogeneity of t
The present invent
A. Field of the In
Q: How to get tex

--- title: 'Change
The invention rela
On this page, you
The present invent
Q: How to remove
Oakland Raiders NF
Laparoscopic appen
Travelling is part
Introduction {#s1}
A typical conventi
Q: How can i add a custom font for a specific font attribute in swift I use a custom font in my app and i want to set a different custom font for a specific font attribute. Like: titleFont = UIFont(name: "YashiraThin", size: 19) So far, this is how i got it, but i don't know how to add the second font, the one i want to use for a specific part of my app. var titleFont = UIFont(name: "Yashira", size: 19) A: You can access each attribute and change it using an NSMutableAttributedString. For example, you could change the font size like this: let size = (titleFont.fontAttributes[.fontSize] as! NSNumber).floatValue var string = "\(NSStringFromClass(type(of: titleText)).description)" string = string.replacingOccurrences(of: "\n", with: "\n\n") var attributedString = NSMutableAttributedString(string: string, attributes: [NSAttributedStringKey.font: titleFont]) attributedString.addAttributes([NSAttributedStringKey.font: UIFont(name: "Arial", size: 14.0)], range: NSMakeRange(0, attributedString.string.characters.count)) You can then set the attributedString as the attributedText for the label: lbl.attributedText = attributedString Where lbl is your label. A: Swift 4.2 Update Based on your response to my comment here is another option: You can create a global UIFont object like so: var titleFont = UIFont(name: "Yashira", size: 19) then if you want to change your titleFont to be another font for the size range 19-25, you can do so: titleFont.withSize(20) or in my case I wanted a font size between 18 and 25, so i created an extension with a guard: extension UIFont { func changeFontSizeTo(size: Float) { guard size < 25, let currentSize = self.pointSize else { return } var newSize = currentSize + (size - currentSize / 3) newSize += (size - newSize) / 3 self.withSize(newSize) } } Now you can use the newFontSize on any of your text as follows: var str = "some text" var currentSize = str.pointSize str.changeFontSizeTo(18) or you can call the extension on the titleFont like this: titleFont.changeFontSizeTo(22) Also keep in mind that i used this method in a separate class so that i could access this outside of the scope of the viewDidLoad of the ViewController. A: So there are multiple ways to achieve this, one is by implementing a category on UIFont, however there are better ways like the one by @MartinR suggested, which will actually create a new font and assign it to the label. For example: var titleFont = UIFont(name: "Yashira", size: 19) let myLabel = UILabel() let changeTo = UIFont(name: "Arial", size: 20) let changeFrom = UIFont(name: "Arial", size: 18) myLabel.font = changeTo Or you can create a method which takes two UIFont instances as input and outputs a third one: func myMethod(from: UIFont, to: UIFont) -> UIFont { return from.withSize(to.pointSize) } and call it like: myLabel.font = myMethod(from: titleFont, to: UIFont(name: "Arial", size: 18)) Note that myMethod may crash if the sizes are not convertible. An improved version of myMethod, without the crash, which will try to convert sizes from one type to the other. The implementation below is actually made of two categories on UIFont. extension UIFont { func withSize(size: CGFloat) -> UIFont { return self.withSize(size, effectiveRange: nil) } func withSize(size: CGFloat, effectiveRange: NSRange?) -> UIFont { guard let effectiveRange = effectiveRange else { let errorMessage = "The new size \(size) is not supported for this font. If you need to change the font size you should use the method \U{2026}" print(errorMessage) return UIFont() } guard let theRange = NSRange(location: 0, length: effectiveRange.length) else { return UIFont() } let newPointSize = UIFont.conversionPointSize(CGFloat(size)) let newFont = UIFont.systemFont(ofSize: newPointSize, weight: UIFont.Weight.thin, design: UIFont.DesignAttribute.systemFont) let fromRange = NSRange(location: effectiveRange.location, length: effectiveRange.length - newPointSize) newFont.getEmojiAndSymbolRanges(from: fromRange) return newFont } } It takes a UIFont with an input UIFont, a CGFloat size to be applied and a UIFontDescriptor initalizer. It searches the fontDescriptor of the current font for the font of that size (if there is any) and if that doesn't work it tries to copy it from another font. Note that I am using emoji/symbols ranges because they use a smaller point size than regular fonts.