LoginSignup
0
2

More than 1 year has passed since last update.

SwiftUI で ToolbarItem の色を変更する

Last updated at Posted at 2021-05-06

実装法

以下のように直接指定してもデフォルト色から変わってくれない

ToolbarItem(placement: .navigationBarLeading){
  Button(action: {} ) {
    Image(systemName: "gearshape")
  }.accentColor(.red)
}

NavigationView に対して accentColor を指定するといける

NavigationView {
  // 省略 //
}
.accentColor(.red)

実装例

import SwiftUI

struct HomeView: View {

  var body: some View {
    NavigationView {
      Text("Hello")
      .navigationBarTitleDisplayMode(.inline)
      .navigationTitle("タイトル")
      .toolbar {
        ToolbarItem(placement: .navigationBarTrailing){
          Button(action: {} ) {
            Image(systemName: "gearshape")
          }
        }
      }
    }
    .accentColor(.red)

  }
}

スクリーンショット 2021-05-06 16.33.39.png

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