2017-02-23 140 views
0

在我的應用程序中,我自定義了我的TableViewCell以顯示卡片。我還爲這些單元實施了自定義UITableViewRowActions。然而,這些動作看起來很奇怪,因爲我添加了一個圖層來使單元格看起來像一張浮動卡片。如何調整UITableViewRowAction的大小以適應自定義大小的tableViewCell? - Swift 3

Here's what it looks like 這裏是我的代碼爲我的cellForRowAt函數。

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "someCell", for: indexPath) as! CustomCell 
     cell.delegate = self 

     cell.backgroundColor = .clear 
     cell.contentView.backgroundColor = .clear 

     let whiteRoundedView: UIView = UIView(frame: CGRect(x: 10, y: 8, width: self.view.frame.size.width - 20, height: cell.frame.size.height - 20)) 
     whiteRoundedView.layer.backgroundColor = CGColor(colorSpace: CGColorSpaceCreateDeviceRGB(), components: [1.0, 1.0, 1.0, 0.9]) 
     whiteRoundedView.layer.masksToBounds = false 
     whiteRoundedView.layer.cornerRadius = 2.0 
     whiteRoundedView.layer.shadowOffset = CGSize(width: -1, height: 1) 
     whiteRoundedView.layer.shadowOpacity = 0.2 
     cell.contentView.addSubview(whiteRoundedView) 
     cell.contentView.sendSubview(toBack: whiteRoundedView) 

     cell.updateCell() 
     return cell 
    } 

和我的UITableViewRowAction函數。預警:我用這SwipeCellKit

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? { 
     if orientation == .left { 
      guard isSwipeRightEnabled else { return nil } 
      let completeAction = SwipeAction(style: .default, title: "Complete") { (action, index) in 
       print("complete!") 

      } 
      completeAction.backgroundColor = .green 
      return [completeAction] 
     } else { 
      let deleteAction = SwipeAction(style: .destructive, title: "Delete") { (action, index) in 
       print("delete") 
      } 
      return [deleteAction] 
     } 
    } 

有什麼辦法來調整UITableViewRowAction以適應單元格的黴菌?

+0

希望這個答案可以幫助你:http://stackoverflow.com/a/12511432/1931317 – Deepak

回答

0

如果不對框架進行一些更改,目前是不可能的。

我確實有計劃在SwipeTableViewCellDelegate中添加一些方法,這些方法會在顯示之前公開每個UIButton,並且隨着刷卡的繼續發生。我想這會給你足夠的靈活性來實現你的佈局。

在此期間,您應該不會太難做到。具體來說,看看SwipeTableViewCell,在configureActionView的方法裏面。它創建SwipeActionsView其中包含buttons屬性包含滑動UIButton子類。你只需要將它們暴露給你的應用程序。

相關問題