Custom UI TableViewCell selected backgroundcolor swift

前端 未结 11 968
盖世英雄少女心
盖世英雄少女心 2020-12-28 16:51

I am trying to change the appearance of a custom selected TableViewCell using Swift.

Do I need to do it via the designer or programmatically?

I tried the fol

11条回答
  •  心在旅途
    2020-12-28 17:16

    The correct (more native & natural) way to do it:

    override func awakeFromNib() {
        super.awakeFromNib()
        selectedBackgroundView = UIView()
        selectedBackgroundView?.backgroundColor = .blue
    }
    

    Why other approaches are wrong:

    1. Highlight solution: highlight is not select. Highlight doesn't animate as Selection does. It doesn't feel natural as a normal Selection would do
    2. No need to change the color of selectedBackgroundView in setSelected method, because iOS handles the animation for us.
    3. Setting backgroundColor also doesn't behave the same as iOS does it

提交回复
热议问题