Search code examples
iosswiftfontsuitableviewrowaction

UITableViewRowAction customise title font size in Swift


I have an edit and a delete tableViewRowAction in my tableViewCell. Currently I'm using the built in emojis to use as my title, but it is too small. How do I make the font larger?

I know we can only customise a limited amount of things in the tableViewRowAction. But is there a way to go around it to make just the title font bigger?

I checked other threads and most of them used:

UIButton.appearance().setAttributedTitle(NSAttributedString(string: "Your Button", attributes: attributes), forState: .Normal)

with a set attribute that determines the font size of course. However, this affects ALL buttons, and that isn't good.

Any help is much appreciated! Thanks!


Solution

  • you are setting this to UIButton so it is set for all UIButton objects.

    You can set it for specific button object like,

      let myButton: UIButton = UIButton()  //your button here
      let attributedStr: NSAttributedString = NSAttributedString()
      myButton.setAttributedTitle(attributedStr, forState: .Normal)
    

    Update :

    You can set title as attributed string.

    check Apple documentation for that and refer this answer for more details

    Hope this will help :)