skip to Main Content

I’m a beginner with swift and have reviewed this site to understand how importing custom fonts work. I’ve also reviewed this StackOverflow question which didn’t seem to solve my specific issue

Upon reviewing the site, I’ve added the .tts file Lovelo-Black to the project and plist.

        private let loginButton: UIButton = {
        let button = UIButton()
        button.setTitle("log in", for: .normal)
        button.layer.masksToBounds = true
        button.layer.cornerRadius = Constants.cornerRadius
        button.backgroundColor = UIColorFromHex(rgbValue: 0x00FF9C,alpha: 1)
        button.setTitleColor(.black, for: .normal)
        button.titleLabel?.font = UIFont(name: "Lovelo-Black") //issue here
        return button

Is it possible to make the button use the Lovelo-Black font? Ideally, I would like it to look like thislogin image

If it is possible, what should I replace the 8th line with?

2

Answers


  1. Make sure you add the fonts correctly to your project..

    check this link

    Use the correct font name

    enter image description here

    button.titleLabel?.font = UIFont(name: "Lovelo Black", size: size)

    Login or Signup to reply.
  2. In swiftUI you can use custom function from Font to initialise and use any custom fonts. have a look at bellow example code.

    Font.custom("Lovelo_Black", size: 24)
    

    Which generates bellow result

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search