LoginSignup
32
32

More than 5 years have passed since last update.

【Xcode8】カスタムフォントを使用する方法

Last updated at Posted at 2016-12-03

イメージ

スクリーンショット 2016-12-03 21.35.16-min.png

設定

1. フォントファイルをXcodeのプロジェクトにドラッグ&ドロップで追加。

スクリーンショット 2016-12-03 21.49.27-min.png

2. TARGETS → Build → Copy Bundle Resources → +ボタンから先程追加したフォントファイルを追加。

スクリーンショット 2016-12-03 21.54.32-min.png

スクリーンショット 2016-12-03 21.57.17-min.png

StoryBoardでフォントを指定する

Labelの設定で「Font」をCustomにして「Family」で追加したフォントを指定します。
スクリーンショット 2016-12-03 22.47.53.png

コードでフォントを指定する

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let customFont: UILabel = UILabel(frame: CGRect(x: 100, y: 100, width: 200, height: 100))
        customFont.text = "かすたむふぉんと"
        // UIFontのnameで追加したフォント名を指定します。
        customFont.font = UIFont(name: "Alice", size: 50)
        self.view.addSubview(customFont)
    }
}

使用できるフォント

.ttf
.oft
以上の2種類になります。
.ttcも使えるとの情報もありましたが未確認です。

フォントファイルの場所の確認方法

まずアプリケーションからFont Bookを開きます。
スクリーンショット 2016-12-03 22.02.02-min.png

該当のフォントを選択し、左上のiマークをクリック。右側の「場所」という項目がフォントがある場所になります。
スクリーンショット 2016-12-03 22.02.34-min.png

フォントによっては先程の「場所」という項目がない場合があります。
その場合はフォントの上にカーソルを合わせると「パス」という項目が出てきますので、そちらで確認することができます。
スクリーンショット 2016-12-03 22.03.02.png

32
32
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
32
32