anz blog

Xcode11&iOS13からUITableViewCell選択時のSelectedColor反映挙動が変わった

2019-11-19 #Xcode

ざっくりまとめ。

  • iOS 13 から UITableViewCell を選択した時の SelectedColor の反映の挙動が変わった
  • iOS 12.x までは contentView の subview 全てに対して SelectedColor が反映された
  • iOS 13 からは contentView までの反映でとどまる

です。

環境

  • Xcode v11.2.1

詳細

どうやら iOS 13 から UITableViewCell を選択した時の SelectedColor の反映の挙動が変わった模様です。

iOS 12.x までは contentView の subview 全てに対して SelectedColor が反映されたいたのですが、
iOS 13 からは contentView までの反映でとどまるようになりました。

この変更はiOS 13 Release Noteにも記載があるので、仕様変更と認識しておいて問題ないと思います。

The UITableViewCell class no longer changes the backgroundColor or isOpaque properties of the contentView and any of its subviews when cells become highlighted or selected. If you are setting an opaque backgroundColor on any subviews of the cell inside (and including) the contentView, the appearance when the cell becomes highlighted or selected might be affected. The simplest way to resolve any issues with your subviews is to ensure their backgroundColor is set to nil or clear, and their opaque property is false. However, if needed you can override the setHighlighted(_:animated:) and setSelected(_:animated:) methods to manually change these properties on your subviews when moving to or from the highlighted and selected states. (13955336)

iOS 12.x

iOS 13.x


これがどのように影響を及ぼすのかは、それぞれのプロジェクトでどのような構成でCellを構築しているのか、
などに影響するので一概にはいえないですが、iOS 13.x と iOS 12.x 以下でちゃんと確認する必要がでてくるので注意しましょう!!
ダークモード関連でここらがかわったのかなぁとか根拠もなく思っています(笑)