Use custom font in swift [closed]

大兔子大兔子 提交于 2020-11-30 11:56:32

问题


I need a font for swift sprite kit, iOS. this font is for commercial purposes and im trying to have a kind of arcade font. I would want to create my own font, or to get a public font which i can use for commercial purposes, and how do I install this font, how do I implement it on swift. Thank you.


回答1:


Fist make sure that your font is .ttf or .otf format

  1. Import your font into the project
  2. Add new key "Fonts provided by application" on application's info.plist file and add your font names Now you can use custom fonts with interface builder or programatically

yourLabel.font = UIFont.init(name: YourFont, size: size)



回答2:


  1. First of all you need to drag the font into the project.
  2. After that you need to select the font and select the target Membership checkmark for your app as seen in the picture.

  1. After that you go to your Info.plist and add the Name of the font in "Fonts Provided By Application"

  2. Now you can finally use the font als you would use every other font. If it doesn't work as ir should you can find out the name Xcode gave the font with

    for name in UIFont.familyNames() {
      println(name)
      if let nameString = name as? String
    
    {
    
        println(UIFont.fontNamesForFamilyName(nameString))
      }
    }
    

UPDATE

The Font is called Fipps-Regular and 100% free to use Download here




回答3:


i would like to add this code if you know your font family name (which you can see in the fontPicker in the IterfaceBuilder) use this to apply the font programatically

func apply_font(FontFamilyName:String)
{
  label.font = UIFont(name: UIFont.fontNames(forFamilyName: 
  **FontFamilyName**)[0], size: 15)
}


来源:https://stackoverflow.com/questions/32060384/use-custom-font-in-swift

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!