1

I have a Label with custom font Unica One-Regular. Since, it is not available in bold font, I am getting problem to make it bold. Is there any way to make it bold?. Here is the font link.

https://fonts.google.com/specimen/Unica+One?selection.family=Unica+One

Thanks in advance.

Harish Singh
  • 765
  • 1
  • 12
  • 23
  • Possible duplicate of [How do I create a bold UIFont from a regular UIFont?](https://stackoverflow.com/questions/16015916/how-do-i-create-a-bold-uifont-from-a-regular-uifont) – Tamás Sengel Mar 27 '18 at 21:12
  • In essence: if the font does not have a bold variation, then it's not possible, at least not in an easy way. – Tamás Sengel Mar 27 '18 at 21:13

2 Answers2

0

Sorry I’m on my iPhone but, Please check the exact name of the font on Xcode, but this code should answer your question :

let attrs:[String:AnyObject] = [NSFontAttributeName: UIFont(name: "Unica One-Bold", size: 12)!]
        let boldString = NSMutableAttributedString(string: "text", attributes:attrs)
let lbl = UILabel()
lbl.attributedText = boldString
Vjardel
  • 1,065
  • 1
  • 13
  • 28
  • 1
    Unica one-Regular is not the System font. It's google font. I have added this font to the project. And it is not available for Bold. If I use above code, I will get crash. Because, "Unica One-Bold" is not available. – Harish Singh Mar 28 '18 at 05:33
0

There is a more recent answer to this question at Is it possible to increase the boldness of the font if the bold font file is not available?.

Short summary: if you have a list of font attributes, you can add a negative stroke width. For example (in Swift):

import AppKit

guard let chosenFont = NSFont(name: "VTypewriter Underwood", size: 24) else {
    print("No such font")
    exit(1)
}
var fontAttributes = [
    NSAttributedString.Key.font:chosenFont,
    NSAttributedString.Key.strokeWidth:NSNumber(value:-3.0)
]
let fakelyBoldedText = NSAttributedString(string:"Hello World", attributes:fontAttributes)

This is not optimal; it isn’t really bolding. But with low values for the stroke width (in my experiments, from about -3 to -5, possibly relative to the font width), it does look bolded.

Jerry Stratton
  • 3,287
  • 1
  • 22
  • 30