How to change UITableViewRowAction title color?

后端 未结 10 890
梦如初夏
梦如初夏 2020-11-30 05:49

Am using UITableViewRowAction in \"editActionsForRowAtIndexPath\" method. I can change the backgroundcolor of UITableViewRowAction, but am not able to change the title color

10条回答
  •  猫巷女王i
    2020-11-30 06:30

    iOS 11 solution:

    Create UITableViewCell extension like this:

    extension UITableViewCell {
    
        /// Returns label of cell action button.
        ///
        /// Use this property to set cell action button label color.
        var cellActionButtonLabel: UILabel? {
            for subview in self.superview?.subviews ?? [] {
                if String(describing: subview).range(of: "UISwipeActionPullView") != nil {
                    for view in subview.subviews {
                        if String(describing: view).range(of: "UISwipeActionStandardButton") != nil {
                            for sub in view.subviews {
                                if let label = sub as? UILabel {
                                    return label
                                }
                            }
                        }
                    }
                }
            }
            return nil
        }
    
    }
    

    And write this in your UITableViewCell

    override func layoutSubviews() {
        super.layoutSubviews()
        cellActionButtonLabel?.textColor = .red
    }
    

    But there is a bug - if you pull the cell fast this code sometimes doesn't change the color.

提交回复
热议问题