Lord Vermillion
Lord Vermillion

Reputation: 5424

Xcode custom fonts not showing up in Storyboard

I added my two fonts to my project folder:

enter image description here

I added them to info.plist:

enter image description here

I can not see them in my custom font list in the storyboard:

enter image description here

What have i done wrong?

Upvotes: 56

Views: 39935

Answers (20)

Caksu
Caksu

Reputation: 1

I was trying to add a custom font in Xcode 16.2 and failed to set in custom font from the storyboard but I can add font files to the project. So the answers for it will be

Poppins = [
"Poppins-Regular", 
"Poppins-Thin", 
"Poppins-Light", 
"Poppins-Medium", 
"Poppins-SemiBold", 
"Poppins-Bold", 
"Poppins-ExtraBold"
]

Upvotes: -1

David Wilson
David Wilson

Reputation: 128

macOS 15.2 / Xcode 16.2 - and the font issue persists. I've found a working solution (in app) for me that works. To be clear this is for a macOS app... I'm yet to test on iOS.

I do want this to work in Interface Builder / Storyboard... for now I'll take what I can get.

Line of code to assign the specific font to the NSTextField

self.signMessage.font = [NSFont fontWithName:@"TrafficNZ" size:36.0];

Info.plist - this does not work

<key>ATSApplicationFontsPath</key>
        <array>
            <string>TrafficNZ_Regular.ttf</string>
        </array>

Info.plist - this does work

<key>ATSApplicationFontsPath</key>
    <string>TrafficNZ_Regular.ttf</string>

I need to see if the font will turn up in Interface Builder. As I'd prefer not to have the line of code. And the array/string property - may work if there is more than one font?

I hope this helps someone out.

  • David

Upvotes: 0

Peter Lapisu
Peter Lapisu

Reputation: 21005

in Xcode 15.4 nothing worked for me...

had to change the font to smth easy searchable and than opened the storyboard as source, searched up the marker font and replaced with the name i wanted

<fontDescription key="fontDescription" name="LuminSansStd" family="Lumin Sans Std" pointSize="16"/>

Upvotes: 0

stackich
stackich

Reputation: 5297

Xcode 15:

Just close the storyboard and reopen it, no need to restart Xcode.

If this does not help, try setting some other font before closing the storyboard and repeat the steps.

Upvotes: 0

Hemant Garg
Hemant Garg

Reputation: 36

It happened with me as well on Xcode 15.4. I tried all the solutions listed above plus other solutions mentioned on developer forum. At the end the best workaround to solve this issue was to add fonts using @IBInspectable

Here is my code to set custom fonts through Storyboard/xib/attributes inspector

import UIKit

protocol FontApplicable {
    func setFont(name: String, size: CGFloat)
}

extension FontApplicable where Self: UIView {
    func setFont(name: String, size: CGFloat) {
        if let textField = self as? UITextField {
            textField.font = UIFont(name: name, size: size)
        } else if let label = self as? UILabel {
            label.font = UIFont(name: name, size: size)
        } else if let button = self as? UIButton {
            button.titleLabel?.font = UIFont(name: name, size: size)
        }
    }
}

// Common extension for UITextField, UILabel, and UIButton
extension UITextField: FontApplicable {}
extension UILabel: FontApplicable {}
extension UIButton: FontApplicable {}

extension UIView {
    @IBInspectable
    var rajdhaniBold: CGFloat {
        set {
            (self as? FontApplicable)?.setFont(name: "Rajdhani-Bold", size: newValue)
        }
        get {
            return 0.0
        }
    }

    @IBInspectable
    var rajdhaniLight: CGFloat {
        set {
            (self as? FontApplicable)?.setFont(name: "Rajdhani-Light", size: newValue)
        }
        get {
            return 0.0
        }
    }

    @IBInspectable
    var rajdhaniMedium: CGFloat {
        set {
            (self as? FontApplicable)?.setFont(name: "Rajdhani-Medium", size: newValue)
        }
        get {
            return 0.0
        }
    }

    @IBInspectable
    var rajdhaniRegular: CGFloat {
        set {
            (self as? FontApplicable)?.setFont(name: "Rajdhani-Regular", size: newValue)
        }
        get {
            return 0.0
        }
    }

    @IBInspectable
    var rajdhaniSemiBold: CGFloat {
        set {
            (self as? FontApplicable)?.setFont(name: "Rajdhani-SemiBold", size: newValue)
        }
        get {
            return 0.0
        }
    }
}

Upvotes: 1

Pelanes
Pelanes

Reputation: 3477

Restart the computer was the only way to restore custom fonts on Xcode 15.4.

Upvotes: -1

ov1d1u
ov1d1u

Reputation: 1077

What worked for me was to add a key named "Application fonts resource path" to the Info.plist file with an empty value.

Upvotes: 1

Merricat
Merricat

Reputation: 2851

Custom fonts show up at the very top!

I think maybe Apple changed it, but it seems that custom fonts show up at the very top of the list. No wonder I couldn't find them alphabetically :)

Upvotes: 4

Mohamed Salah
Mohamed Salah

Reputation: 1205

In my case my fonts were in woff2 formats. Although woff2 is supported in iOS, the fonts don't appear or get rendered in Storyboards.

Upvotes: 0

Dylan
Dylan

Reputation: 1348

In my case I just turn the text from plain to attributed then turn it back again to plain then it showed up., hope this help anyone.

Upvotes: 10

kalpa
kalpa

Reputation: 982

I ran into the same issue and fixed with below steps

  1. Closed storyboard
  2. Cleared derived data
  3. Cleaned the project and open the story board

If this is not working then restart the Xcode.

Thanks

Upvotes: 5

Luat Vu Dinh
Luat Vu Dinh

Reputation: 480

Sometime I go to another file and come back, then my custom fonts are arrived. I think this is an issue of Xcode and will be solved in following version.

Upvotes: 2

Mohan Ramanathan
Mohan Ramanathan

Reputation: 2209

I Installed the font in the system as per DarkDust solution and i am able to see the font in attributed type.

Then i changed the type to plain and i able to see the Custom font in the font types drop down.

Upvotes: 7

Ryan H
Ryan H

Reputation: 1756

Well, silly mistake on my part, but I didn't realize my font was named something way different from the file name.

Double-clicking the actual font file opened it in the font book, and that showed the actual font name. It was in the dropdown all along.

Upvotes: 3

Jordan Kinsley
Jordan Kinsley

Reputation: 109

This was a huge headache for me but I simply fixed it by: I fixed the issue by restarting my Mac. Then restarting Xcode.

Upvotes: 5

Sean Dev
Sean Dev

Reputation: 1309

Had the same problem but this SO answer by user Saranjith solved it while the other solutions in this thread didn't: Xcode 8 custom font doesn't show up in interface builder

Basically in Font Book select "Computer Fonts" and then hit the + button and re add the Fonts.

This is happened to me after moving to Xcode 11 in Catalina from Xcode 10 in Mojave.

Upvotes: 4

Serega
Serega

Reputation: 650

If Xcode showed your custom font before but stopped to do it at some moment, try to readd font files to your project. It solved the problem for me. Other answers weren't helpful.

Upvotes: 0

ethemsulan
ethemsulan

Reputation: 2319

I solved my problem when i used font name. Do not use file name. I was used like this [UIFont fontWithName:@"appFont" size:17] but it is wrong.

  1. Upload your font file to https://fontdrop.info/ and use the name
  2. My font file name is appFont.ttf but when i uploaded i saw Roboto Regular.
  3. [UIFont fontWithName:@"Roboto Regular" size:17]

Upvotes: 2

DS.
DS.

Reputation: 3004

I know this is a pretty old question, but I ran into the same issue. And the above tips didn't work for me. Apart from the standard checks (present in bundle, restarting XCode, the thing that fixed my issue was that my label text type was marked as "Plain" and hence some fonts were not showing in the dropdown in the Storyboard. As soon as I changed the text type to "Attributed", all the fonts appeared in the dropdown.

Hope this'll help someone stuck with the same issue.

Upvotes: 102

DarkDust
DarkDust

Reputation: 92384

This drop-down box shows the system-wide installed fonts. So you need to install your custom font on your system first so it's appearing in that drop-down box. You can do that by double-clicking it, the FontBook.app opens and asks you whether you want to install the font.

Upvotes: 31

Related Questions