2016-05-30 2 views
0

Я хочу изменить цвет заголовка 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] 

    } 
+0

Там нет (общественных) API для 'UITableViewRowAction', чтобы сделать это. Я бы предложил использовать одну из многих фреймворков (в настоящее время я использую «SWTableViewCell», но есть множество опций). – sschale

+0

Этот ответ, из упомянутого вопроса @sschale, должен сработать для вас: http://stackoverflow.com/a/36145706/5143847 – penatheboss

ответ

0

С UITableViewRowAction является тип UIButton мы можем изменить цвет текста, изменяя внешний вид UIButton класса. добавьте следующий код в свой editActionsForRowAtIndexPath

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

ВЫВОД:

enter image description here

+0

не изменяет ли цвет каждой кнопки в приложении? – Nathan

+0

Да, он изменяет все UIButton – Gokul

+1

@Nathan, вы меняете только кнопки внутри вашей таблицы представления таблицы с помощью UIButton.appearance (whenContainedInInstancesOf: [YourCustomUITableCell.self]). SetTitleColor (UIColor.redColor(), forState: UIControlState.Normal) –