LoginSignup
2
3

More than 1 year has passed since last update.

【Swift】Fontファイルを読み込んで使う

Last updated at Posted at 2022-04-21

XCodeにFontファイルを取り込む

スクリーンショット 2022-04-21 22.36.59.png

  • Copy items if needed
  • Create groups
  • Create folder referenses
  • Add to targets

スクリーンショット 2022-04-21 22.37.27.png

こんな感じで取り込めたらOKです

Info.plistでFontの設定

スクリーンショット 2022-04-21 23.01.55.png
ここで設定するFontの名前は拡張子までです
スクリーンショット 2022-04-21 23.04.00.png
一応ズームした画像も載せておきます

<dict>
	<key>UIAppFonts</key>
	<array>
		<string>JF-Dot-jiskan24h.ttf</string>
	</array>
</dict>

Source Codeで開くとこうなります

Copy Bundle Resourceに追加

スクリーンショット 2022-04-21 22.54.29.png
+を押します
スクリーンショット 2022-04-21 22.56.41.png
使用したいFontファイルを選択して「Add」を押します

以上で準備は完了です。

使い方

SwiftUI

import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("こんにちは")
            .font(.custom("JF-Dot-jiskan24h", size: 25))
    }
}

UIKit

import UIKit

class ViewController: UIViewController {
    @IBOutlet var label: UILabel!
    override func viewDidLoad() {
        super.viewDidLoad()
        label.text = "こんにちは"
        label.font = UIFont(name: "JF-Dot-jiskan24h", size: 25)
    }
}

おわり

今回サンプルとして使用させて頂いたのはこちらの「JFドットjiskan24h」というFontです
ありがとうございます

このフォントを使ってアプリを公開してますので是非使ってみてください

2
3
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
2
3