LoginSignup
0
1

More than 1 year has passed since last update.

【SwiftUI】TabViewに色を付ける

Posted at

はじめに

iOS15からTabが透明になりました。

  • iOS14と同じ見た目にする方法
  • Tabに色を付ける方法

この二つを紹介します

iOS14と同じ見た目にする方法

struct ContentView: View {
+   init() {
+       let appearance: UITabBarAppearance = UITabBarAppearance()
+       appearance.configureWithDefaultBackground()
+       UITabBar.appearance().scrollEdgeAppearance = appearance
+       UITabBar.appearance().standardAppearance = appearance
+   }
    var body: some View {
        TabView {
            HomeView()
                .tabItem {
                    Image(systemName: "house")
                    Text("ホーム")
                }
            SearchView()
                .tabItem {
                    Image(systemName: "magnifyingglass")
                    Text("検索")
                }
            SettingView()
                .tabItem {
                    Image(systemName: "gearshape")
                    Text("設定")
                }
        }
    }
}

simulator_screenshot_39938D38-6C94-489D-AB3D-C7B375108F2A.png

Tabに色を付ける方法

import SwiftUI

struct ContentView: View {
+   init() {
+       let appearance: UITabBarAppearance = UITabBarAppearance()
+       appearance.backgroundColor = .yellow
+       UITabBar.appearance().scrollEdgeAppearance = appearance
+       UITabBar.appearance().standardAppearance = appearance
+   }
    var body: some View {
        TabView {
            HomeView()
                .tabItem {
                    Image(systemName: "house")
                    Text("ホーム")
                }
            SearchView()
                .tabItem {
                    Image(systemName: "magnifyingglass")
                    Text("検索")
                }
            SettingView()
                .tabItem {
                    Image(systemName: "gearshape")
                    Text("設定")
                }
        }
    }
}

simulator_screenshot_A3059413-5963-4455-87D7-07ABEE14C07D.png

おわり

iOS15の標準 iOS14の標準 色付き
simulator_screenshot_DDBB0361-13AF-4BA7-AB3B-5364499A4BB6.png simulator_screenshot_39938D38-6C94-489D-AB3D-C7B375108F2A.png simulator_screenshot_A3059413-5963-4455-87D7-07ABEE14C07D.png
0
1
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
1