2016-03-11 60 views
2

我已經搜查了這個問題,但我發現的是:如何將圖像放在UITableViewRowAction標題之上?

  1. 如何把圖像作爲行操作的背景。

  2. 如何把Unicode字符\ u {unicode在這裏}。它的工作,但我 無法找到一個Unicode字符來表示一個添加按鈕,或一個 刪除按鈕也許。

但我想要的是將自定義圖像放在行動作標題的頂部。例如:一個垃圾桶,其標題將在其下方刪除。

我試過這個代碼太:

"\(UIImage(named: "trashImg"))" 

在行操作標題字符串,但Xcode中似乎沒有算上最後一個)作爲代碼的一部分,但只是作爲字符串的一部分。但無論如何,我建立了這個項目,當我測試時,而不是標題,有一個巨大的文字說「可選:(64,)....」等,它沒有崩潰壽。

請幫助我,許多應用程序這樣做,我也希望它在我的!

在此先感謝。

回答

0

您正在將圖像放入一個字符串對象,該對象將獲得該圖像的默認字符串表示形式。

也許這篇文章可能會有所幫助。看起來他們正在重寫editActionsForRowAtIndexPath並使用patternimage設置背景色。 Custom table view row action (image)

另一篇文章說基本上是一回事UITableViewRowAction image for title

+0

我已經試過,但它只是使圖像成爲背景,而不是它出現。 –

+0

這聽起來像你可能只需要創建一個自定義的UITableViewCell並將您自己的自定義按鈕的圖像和標題放在單元格右側。是否有一個原因,你必須使用editAction? – bhmahler

2

您需要根據您的需求來改變插圖。

class TableViewRowAction: UITableViewRowAction 
{ 
    var image: UIImage? 

    func _setButton(button: UIButton) { 

     if let image = image, let titleLabel = button.titleLabel { 

      let labelString = NSString(string: titleLabel.text!) 
      let titleSize = labelString.sizeWithAttributes([NSFontAttributeName: titleLabel.font]) 
      button.tintColor = UIColor.whiteColor() 
      button.setImage(image.imageWithRenderingMode(.AlwaysTemplate), forState: .Normal) 
      button.imageEdgeInsets.right = -titleSize.width 
     } 
    } 
} 


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


    let moreRowAction = TableViewRowAction(style: UITableViewRowActionStyle.Default, title: "  ") { action, indexPath in 
     // Action Block of more button. 
    } 

    moreRowAction.image = UIImage(named: "edit_white") 
    moreRowAction.backgroundColor = UIColor(red: 252/255, green: 65/255, blue: 75/255, alpha: 1.0) 



    let deleteRowAction = TableViewRowAction(style: UITableViewRowActionStyle.Default, title: "  ") { action, indexPath in 
      // Action Block of delete button. 

    } 

    deleteRowAction.backgroundColor = UIColor(red: 252/255, green: 65/255, blue: 75/255, alpha: 1.0) 
    deleteRowAction.image = UIImage(named: "delete_white") 

    return [deleteRowAction, moreRowAction] 

} 
+0

不能在ios中工作11 –

相關問題