更改UITableViewRowAction标题文本的颜色

时间:2016-05-30 18:03:49

标签: ios swift uitableview uitableviewrowaction

我想要更改UITableViewRowAction标题的颜色。我希望“下载”用红色写成。

enter image description here

这是按钮的代码 -

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]

    }

1 个答案:

答案 0 :(得分:0)

由于 UITableViewRowAction 是一种 UIButton ,我们可以通过更改UIButton类外观来更改文本颜色。添加以下代码editActionsForRowAtIndexPath

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

<强>输出:

enter image description here