2017-02-23 4 views
0

私のアプリでは、TableViewCellをカードのように表示するようにカスタマイズしました。私もこれらのセルにカスタムUITableViewRowActionsを実装しました。しかし、私はフローティングカードのように見えるようにレイヤーを追加したので、アクションは奇妙に見えます。カスタムサイズのtableViewCellに合わせてUITableViewRowActionのサイズを変更するにはどうすればよいですか? - 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が公開され、スワイプが続行されます。私はそれがあなたのレイアウトを達成するのに十分な柔軟性を与えると思います。

これは、あまりにもあなた自身のフォークで行うのは難しいことではありません。具体的には、configureActionViewメソッド内のSwipeTableViewCellを参照してください。 SwipeActionsViewが作成され、buttonsスワイプUIButtonサブクラスを含むプロパティがあります。それらをあなたのアプリに公開するだけです。

関連する問題