LoginSignup
1
2

【Swift】NavigationBarのタイトルをカスタマイズ

Last updated at Posted at 2021-11-07

SwiftでNavigationBarのタイトルをカスタマイズする方法。

実際のコード

//タイトルの文言
self.title = "タイトル"
self.navigationController?.navigationBar.titleTextAttributes = [
    //タイトルの文字色
    NSAttributedString.Key.foregroundColor: UIColor.white
    //タイトルのフォントと文字サイズ
    NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 30)
]

今回は文字色とフォント・文字サイズについて触れましたが、他にも種類はたくさんあります。

static let attachment: NSAttributedString.Key
The attachment for the text.

static let backgroundColor: NSAttributedString.Key
The color of the background behind the text.

static let baselineOffset: NSAttributedString.Key
The vertical offset for the position of the text.

static let cursor: NSAttributedString.Key
The cursor object.

static let expansion: NSAttributedString.Key
The expansion factor of the text.

static let font: NSAttributedString.Key
The font of the text.

static let foregroundColor: NSAttributedString.Key
The color of the text.

static let glyphInfo: NSAttributedString.Key
The name of a glyph info object.

static let kern: NSAttributedString.Key
The kerning of the text.
static let ligature: NSAttributedString.Key
The ligature of the text.

static let link: NSAttributedString.Key
The link for the text.

static let markedClauseSegment: NSAttributedString.Key
The index of the marked clause segment.

static let obliqueness: NSAttributedString.Key
The obliqueness of the text.

static let paragraphStyle: NSAttributedString.Key
The paragraph style of the text.

static let shadow: NSAttributedString.Key
The shadow of the text.

static let spellingState: NSAttributedString.Key
The spelling state of the text.

static let strikethroughColor: NSAttributedString.Key
The color of the strikethrough.

static let strikethroughStyle: NSAttributedString.Key
The strikethrough style of the text.

static let strokeColor: NSAttributedString.Key
The color of the stroke.

static let strokeWidth: NSAttributedString.Key
The width of the stroke.

static let superscript: NSAttributedString.Key
The superscript of the text.

static let textAlternatives: NSAttributedString.Key
The alternatives for the text.

static let textEffect: NSAttributedString.Key
The text effect.

static let toolTip: NSAttributedString.Key
The tooltip text.

static let underlineColor: NSAttributedString.Key
The color of the underline.

static let underlineStyle: NSAttributedString.Key
The underline style of the text.

static let verticalGlyphForm: NSAttributedString.Key
The vertical glyph form of the text.

static let writingDirection: NSAttributedString.Key
The writing direction of the text.

https://developer.apple.com/documentation/foundation/nsattributedstring/key

参考

Swiftのお役立ち情報

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