0
2

More than 1 year has passed since last update.

【Swift】Xcodeでカスタムフォントをコードで実装する方法

Last updated at Posted at 2021-11-18

Xcodeでカスタムフォントを使用する方法。

フォントファイルの用意

まずはフォントファイルを手元に用意します。

拡張子はotf ttf ttcのいずれかにしておきましょう。

フォントファイルをアップロード

次に用意したフォントファイルをXcodeにドラッグアンドドロップでアップロードします。

スクリーンショット 2021-11-18 23.17.00.png

上の画像のようにウィンドウが表示されるので、画像のようにチェックを入れてFinishをクリックしましょう。

Swiftコードで実装

アップロードが完了したらSwiftのコードで実装していきます。

private let sampleLabel: UILabel = {
    let label = UILabel()
    label.font = UIFont(name: "フォント名", size: 15)
    label.frame = CGRect(x: 0, y: 0, width: 300, height: 100)
    label.textColor = UIColor.black
    label.textAlignment = .center
    return label
}()

装飾やサイズは適当にしてあります。

参考

おすすめ情報

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