0

I want change the color of UITableViewRowAction title. I want the “Download” to be written in red.

enter image description here

This is the code for the button -

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {


        let downloadButton = UITableViewRowAction(style: .Normal, title: "Download") { action, index in

            var url: String

            if self.searchController.active {
                url = String(self.filteredPapers[indexPath.row].url)
            } else {
                url = String(self.papers[indexPath.row].url)
            }

            url = url.stringByReplacingOccurrencesOfString(" ", withString: "%20")
            print(url)
            let destination = Alamofire.Request.suggestedDownloadDestination(directory: .DocumentDirectory, domain: .UserDomainMask)

            self.table.editing = false

            Alamofire.download(.GET, url, destination: destination).response { _, _, _, error in
                if let error = error {
                    print("Failed with error: \(error)")
                } else {
                    print("Downloaded file successfully")
                }
            }

        }

        downloadButton.backgroundColor = UIColor(red:0.79, green:0.79, blue:0.81, alpha:1.0)


        return [downloadButton]

    }
utkbansal
  • 2,787
  • 2
  • 26
  • 47
  • There's no (public) API for `UITableViewRowAction` to do that. I'd suggest using one of the many swipe frameworks (I currently use `SWTableViewCell`, but there are tons of options). – sschale May 30 '16 at 18:35
  • This answer, from the question @sschale mentioned, should work for you: http://stackoverflow.com/a/36145706/5143847 – Pranav Wadhwa May 30 '16 at 20:24

1 Answers1

0

Since UITableViewRowAction is a type of UIButton we can change text colour by changing the appearance of UIButton class.add the following code in your editActionsForRowAtIndexPath

UIButton.appearance().setTitleColor(UIColor.redColor(), forState: UIControlState.Normal)

OUTPUT:

enter image description here

Gokul G
  • 2,046
  • 15
  • 22
  • 1
    doesn't this change the color of every button in the application? – Nathan Jan 13 '17 at 09:17
  • yes, it changes all UIButton – Gokul G Jan 13 '17 at 09:49
  • 3
    @Nathan, you change only the buttons inside your table view cell by UIButton.appearance(whenContainedInInstancesOf: [YourCustomUITableViewCell.self]).setTitleColor(UIColor.redColor(), forState: UIControlState.Normal) – ThE uSeFuL Oct 19 '17 at 13:32