How to do custom font and color in UITableViewRowAction without Storyboard

前端 未结 9 1818
失恋的感觉
失恋的感觉 2020-12-30 08:09

I have classic TableView where you can delete item if you swipe and than clicking on the button. I know how to set custom background on the cell, but I can\'t find how I can

9条回答
  •  情歌与酒
    2020-12-30 09:01

    You could use UIButton.appearance to style the button inside the row action. Like so:

    let buttonStyle = UIButton.appearance(whenContainedInInstancesOf: [YourViewController.self])
    
    let font = UIFont(name: "Custom-Font-Name", size: 16.0)!
    let string = NSAttributedString(string: "BUTTON TITLE", attributes: [NSAttributedString.Key.font : font, NSAttributedString.Key.foregroundColor : UIColor.green])
    
    buttonStyle.setAttributedTitle(string, for: .normal)
    

    Note: this will affect all of your buttons in this view controller.

提交回复
热议问题