在iOS 13上构建时,UITableViewCell selectedBackgroundView的颜色不可见 [英] UITableViewCell selectedBackgroundView's color not visible when building on iOS 13

查看:38
本文介绍了在iOS 13上构建时,UITableViewCell selectedBackgroundView的颜色不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用

cellForRowAtIndexPath 中为表格视图单元格选择了颜色

 让backgroundView = UIView()backgroundView.backgroundColor = UIColor.grey3//自定义颜色cell.selectedBackgroundView = backgroundView 

由于我使用Xcode 11.0进行构建,因此颜色不再在iOS 13设备或模拟器上传播到单元的子视图.如果我使用Xcode 11.0在iOS 12.2模拟器上构建,它仍然可以正常工作.

任何人都知道发生了什么变化才能导致这种行为?我正在处理.xib文件.

解决方案

来自Apple的

iOS 13:

I have given a tableview cell a color on selection in cellForRowAtIndexPath using

    let backgroundView = UIView()
    backgroundView.backgroundColor = UIColor.grey3 //custom color
    cell.selectedBackgroundView = backgroundView

Since I am building with Xcode 11.0 the color is not propagated to the subviews of the cell anymore on an iOS 13 device or Simulator. If I build on an iOS 12.2 simulator using Xcode 11.0 it still works.

Anyone has an idea what has changed to cause this behaviour? I am working with .xib files.

解决方案

From Apple's iOS 13 Release Notes:

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.

My quick test confirms this would be the cause in your case.

Cell with green-background label, orange view as .selectedBackgroundView.

iOS 12:

iOS 13:

这篇关于在iOS 13上构建时,UITableViewCell selectedBackgroundView的颜色不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆