0

I'm trying to develop a keyboard and it should use a different font then the default one. Here's the line:

   override func textDidChange(textInput: UITextInput?) {

    textInput.font = UIFont(name: "font name", size: 30)

}

But it doesn't work.... How can I fix it? Thanks.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • which font you are using ? – Mayank Patel Jan 23 '16 at 05:26
  • If this were possible I would use a .ttf font I've created. It already works in Swift, but I'm not able the tell the program I want to change the font of the UITextInput.... The problem isn't the font I use, but the line textInput.font is not correct, and throws back an error. Thanks – Lord Nexprex Jan 23 '16 at 07:58

1 Answers1

0

Follow this steps to use custom Fonts

  1. Drag and drop your font into Xcode
  2. Choose options for adding these files: Copy items if needed Create groups Add to targets:(your app name)
  3. In your Info.plist file add a key named: Fonts provided by application, which is an array
  4. Customize your font:

     myUILabel.text = "demoText"
     myUILabel.font = UIFont(name: "myCustomFont.ttf", size: 25)
    
Mayank Patel
  • 3,868
  • 10
  • 36
  • 59
  • Even adding the .ttf in the line still doesn't work: it says: "Value of type 'UITextInput?' has no member 'font'" – Lord Nexprex Jan 23 '16 at 08:31
  • what is it ? please make sure each and every steps you have to follow – Mayank Patel Jan 23 '16 at 08:33
  • I've done every step you suggested, but it doesn't work – Lord Nexprex Jan 23 '16 at 10:37
  • But the problem is that I'm coding for a custom keyboard that should have an output with a font I want to use, and I'm not able to change the font of my output. – Lord Nexprex Jan 23 '16 at 10:53
  • ouch! that's not good to ear... Thanks. (Maybe do you have any suggestion of how to use a custom font?) – Lord Nexprex Jan 23 '16 at 11:48
  • It seems that the problem isn't the font settings: for example I am able to use the font in the same KeyBoardViewController.swift for the buttons of the keyboard. But when I try to use the font for the text that has been written by the user I can't do it without errors. – Lord Nexprex Jan 23 '16 at 15:56
  • @LordNexprex any update for custom font with custom keyboard approach ...had u done …thanks – Pradeep Kashyap Feb 23 '20 at 15:23