UITableViewCell selectedBackgroundView's color not visible when building on iOS 13

后端 未结 3 447
旧巷少年郎
旧巷少年郎 2021-01-05 03:17

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

    let backgroundView = UIView()
    backgroundView.backgroun         


        
3条回答
  •  甜味超标
    2021-01-05 03:56

    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:

提交回复
热议问题