8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【iOS15】タブバーの背景を有効にしたい

Last updated at Posted at 2021-08-13

注意

執筆時点でベータ版を扱っているため、正式版と挙動が異なる可能性があります。

UITabBarAppearanceを使う

Sample.swift
...
let appearance = UITabBarAppearance()
appearance.backgroundColor =  UIColor.gray
UITabBar.appearance().standardAppearance = appearance
UITabBar.appearance().scrollEdgeAppearance = appearance
...

環境

  • Xcode 13.0 beta 5
  • iOS 15.0

背景

iOS 15からUITabBarの背景が取り除かれたため、明示的に背景色を指定する必要があった。

実装にあたり

UITabBarクラスのstandardAppearance (iOS 13.0+)scrollEdgeAppearance (iOS 15.0+)の2つのプロパティにUITabBarAppearanceのインスタンスをセットしてタブバーの背景を有効にする。

standardAppearance (iOS 13.0+)をセットしないとデフォルトの外観(白?)が設定される。
https://developer.apple.com/documentation/uikit/uitabbar/3198046-standardappearance?changes=_7
(The default value of this property is an appearance object containing the system's default appearance settings.)

scrollEdgeAppearance (iOS 15.0+)nilにしてしまうと、背景が透明になる模様。
https://developer.apple.com/documentation/uikit/uitabbar/3750912-scrolledgeappearance?changes=_7
(If the value of this property is nil, UIKit uses the value of the tab bar’s standardAppearance property, modified to have a transparent background.)

参考サイト

8
6
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
8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?