5
0

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 3 years have passed since last update.

スクロール時にUITableViewのヘッダーの背景を透明にする方法

Posted at

問題

UITableViewにて任意のヘッダーが表示されている場合、セルをヘッダーの下に隠れるまでスクロールすると、背景が非透明色に変化するという現象がありました(下図)。
image.png
ヘッダーのcontentView.backgroundColorUIColor.clearに設定するなどを試みましたが、スクロールすると背景色は非透明になってしまいます。

解決策

AppDelegateのapplication(_:didFinishLaunchingWithOptions:)内で下記を記述することで、背景が非透明にならないように設定することができます。

var bgConfig = UIBackgroundConfiguration.listPlainCell()
bgConfig.backgroundColor = UIColor.clear
UITableViewHeaderFooterView.appearance().backgroundConfiguration = bgConfig

おわりに

同じようなことでハマっている方のお役に立てればと思います。
また、認識が間違っているなどのご指摘がありましたら、ご教授いただけますと幸いです。

環境

  • Xcode 13
  • iOS 15.0
  • Swift 5.0

参考

5
0
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
5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?