2017-02-23 198 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子类。你只需要将它们暴露给你的应用程序。

相关问题