Swift SpriteKit 中使用 FontAwesome

来源:互联网 发布:手机淘宝秒杀在哪里 编辑:程序博客网 时间:2024/05/16 16:01

Swift SpriteKit 中使用 FontAwesome

1. FontAwesome.otf加入xCode

直接从Finder中把fontAwesome.otf文件拖入xCode项目下。

直接从Finder中把fontAwesome.otf文件拖入xCode项目下。

2. Copy Bundle Resource

在project->build里面,设置copy bundle resource。

3. 加入plist

这里写图片描述

4. 获取Font名称

override func didMove(to view: SKView) {    for family: String in UIFont.familyNames {            print("\(family)")            for names: String in UIFont.fontNames(forFamilyName: family) {                print("== \(names)")            }        }    }

这里写图片描述

5. 使用字体

public struct FontAwesome {    static let fiveHundredPixels = "\u{f26e}"    static let adjust = "\u{f042}"    static let adn = "\u{f170}"    static let alignCenter = "\u{f037}"    static let alignJustify = "\u{f039}"    static let alignLeft = "\u{f036}"    static let alignRight = "\u{f038}"    static let amazon = "\u{f270}"    static let ambulance = "\u{f0f9}"    ...}let levelMenu = SKLabelNode(fontNamed: "FontAwesome")levelMenu.text = FontAwesome.applelevelMenu.fontColor = UIColor.whitelevelMenu.fontSize = 32levelMenu.position =  CGPoint(x:30,y:5*menuCellHei + (menuCellHei-32)/2)menuNode.addChild(levelMenu)
0 0