2017-06-03 8 views
0

Swift 3でテーブルビューのアクションボタンを垂直に設定するにはどうすればよいですか?Swiftでテーブルビューのアクションボタンを垂直に設定する方法は?

This is my tableview's action buttons looks like。 常にこれはlook likeです。これは水平で、垂直に整列したいと思います。私はこれをどうやって?水平方向の配置と

override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { 
    let RowAction1 = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "action1", handler:{action, indexpath in 
    print("action1") 
    }) 
    RowAction1.backgroundColor = UIColor(red: 0.298, green: 0.51, blue: 0.3922, alpha: 1.0) 

    let RowAction2 = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "action2", handler:{action, indexpath in 
    print("action2") 
    }) 
    RowAction2.backgroundColor = UIColor(red: 0.28, green: 0.851, blue: 0.3922, alpha: 1.0) 

    let RowAction3 = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "action3", handler:{action, indexpath in 
    print("action3") 
    }) 
    RowAction3.backgroundColor = UIColor(red: 0.298, green: 0.81, blue: 0.3922, alpha: 1.0) 

    let RowAction4 = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "action4", handler:{action, indexpath in 
    print("action4") 
    }) 
    RowAction4.backgroundColor = UIColor(red: 0.298, green: 0.851, blue: 0.3922, alpha: 1.0) 

    return [RowAction1, RowAction2, RowAction3, RowAction4] 

} 

答えて

0
+0

はのtableViewのメソッドや関数での解決策はありますか?私はプログラム的に意味する。 – HiKa

+0

stackViewはコードでも完全にカスタマイズ可能です。ちょうど.horigmentプロパティを.horigmentに設定していますね。 –

+0

しかし、私は実際にコード内のUI全体を書くことはどのように役立つのか分かりません。セルが押し出されないようにするには、カスタムxibを作成してください... –

1

CustomCellを作成し、AutoLayoutを使用しないのはなぜ?この例のように、私は以下の作成:

enter image description here

だからあなたは基本的に自分のストーリーボードにあなたのtableView内のカスタムセルを作成し、それを使用します。

let cell = tableView.dequeueReusableCell(withIdentifier: "CustomExampleCell", for: indexPath) as! CustomExampleCell 

あなたは私が作成したサンプルプロジェクトをダウンロードすることができますあなたhere。次のコードを使用スワイプアクセシビリティのためにスウィフトのメソッドで構築を使用するには

更新

override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { 
    return true 
} 

override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { 
    let more = UITableViewRowAction(style: .normal, title: "More") { action, index in 
     print("More") 
    } 
    let share = UITableViewRowAction(style: .normal, title: "Share") { action, index in 
     print("Share") 
    } 
    let delete = UITableViewRowAction(style: .default, title: "Delete") { action, index in 
     print("Delete") 

    } 
    more.backgroundColor = .gray 
    share.backgroundColor = .blue 
    delete.backgroundColor = .red 
    return [delete, share, more] 
} 
+0

私はすでにカスタムセルを使用しています – HiKa

+0

次に、ボタンをスタイルするためにAutoLayoutを使用する方法の例をチェックアウトします。 –

+0

セルにスワイプすると開いているボタンですか? – HiKa

関連する問題