
我的代码:
let label = SKLabelNode(Fontnamed: "gameOver") label.text = "Game Over" label.Fontcolor = SKcolor.redcolor() label.FontSize = 150 label.position = CGPointMake(0,100) label.horizontalAlignmentMode = .Center node.addChild(label)解决方法 这些是向您的应用程序添加自定义字体的步骤:
>在应用程序中添加“gameOver.ttf”字体(Make sure that it’s included in the target)
>修改application-info.pList文件。
>在新行中添加“应用程序提供的字体”键
>并将“gameOver.ttf”添加为数组“应用程序提供的字体”中的新项目。
现在,Interface Builder中将显示该字体。
要在代码中使用自定义字体,我们需要通过名称引用它,但是名称通常与字体的文件名不同
There are 2 ways to find the name:
Install the Font on your Mac. Open Font Book,open the Font and see
what name is Listed. Programmatically List the available Fonts in your app
对于第二种方法添加这一行是你的应用程序代理的dIDFinishLaunchingWithOptions
println(UIFont.familynames())
要列出每个字体系列中包含的字体,在swift 2中:
class func printFonts() { for familyname in UIFont.familynames() { print("\n-- \(familyname) \n") for Fontname in UIFont.FontnamesForFamilyname(familyname) { print(Fontname) } }} 找到您的自定义字体的名称后,您可以使用它:
SKLabelNode(Fontnamed: "gameOver") // put here the correct Font name
或简单的标签:
cell.textLabel?.Font = UIFont(name: "gameOver",size: 16) // put here the correct Font name
Useful resource
总结以上是内存溢出为你收集整理的ios – Swift自定义字体Xcode 7全部内容,希望文章能够帮你解决ios – Swift自定义字体Xcode 7所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)