swiftaccessibilitydynamic-type-feature

Bold dynamic type in Swift


enter image description here

How come for a dynamic font on a UILabel where we have the following:

        artistLabel.font = UIFont.preferredFont(forTextStyle: .body, compatibleWith: UITraitCollection(legibilityWeight: .regular))
        artistLabel.adjustsFontForContentSizeCategory = true
        
        trackLabel.font = UIFont.preferredFont(forTextStyle: .body, compatibleWith: UITraitCollection(legibilityWeight: .bold))
        trackLabel.adjustsFontForContentSizeCategory = true

bold and regular look the same? How can I get a true "bold" font?


Solution

  • You can use a custom font for this.

    Step 1: Add Custom fonts to the project.

    enter image description here

    Step 2: Add these fonts under "Fonts Provided by application" key in info.plist file

    enter image description here

    Step 3: Use it as below.

    For Bold font:

    artistLabel.font = UIFont(name:"ArchSans-Bold", size: fontSize)
    

    For Regular Font:

    artistLabel.font = UIFont(name:"ArchSans", size: fontSize)