gpt4 book ai didi

ios - 我如何在 Swift 中设置我的 tableview 的 Action 按钮垂直对齐?

转载 作者:行者123 更新时间:2023-11-28 15:35:32 25 4
gpt4 key购买 nike

我如何在 Swift 3 中设置我的 tableview 的操作按钮垂直对齐?

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]

}

最佳答案

为什么不创建一个 CustomCell 并使用 AutoLayout?就像我在下面创建的这个例子:

enter image description here

因此,您基本上是在 Storyboard 中的 tableView 中创建一个自定义单元格,然后使用它:

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

您可以下载我为您创建的示例项目here .

更新
要使用 Swift 中的内置方法实现滑动可访问性,请使用以下代码:

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]
}

关于ios - 我如何在 Swift 中设置我的 tableview 的 Action 按钮垂直对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44342319/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com