Swift 自定义 uitabbar 溢出项的 TableViewController
Customise TableViewController of uitabbar overflow items in Swift
UIKit 自动管理来自标签栏的溢出项。当您 select "More" 时,溢出项显示在 TableViewController 中。我正在努力寻找详细说明如何以编程方式自定义此 TableViewController(例如,以适应您的应用程序的样式)的文档或以前的答案?主要是我不确定如何访问此 TableViewController 以便进行自定义。
示例:
您可以尝试类似下面的代码。尝试将 topViewController 的 moreNavigationController 视图作为 UITableView 并将自定义 UITableViewDelegate 设置为它。在委托中,您可以覆盖 WillDisplay 单元格函数来自定义单元格。
class ViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
if let moreListViewController = self.moreNavigationController.topViewController {
if let moreListTableView = moreListViewController.view as? UITableView {
moreListTableView.delegate = self
}
}
}
}
extension ViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.backgroundColor = UIColor.random
}
}
private extension UIColor {
static var random: UIColor {
return .init(hue: .random(in: 0...1), saturation: 1, brightness: 1, alpha: 1)
}
}
UIKit 自动管理来自标签栏的溢出项。当您 select "More" 时,溢出项显示在 TableViewController 中。我正在努力寻找详细说明如何以编程方式自定义此 TableViewController(例如,以适应您的应用程序的样式)的文档或以前的答案?主要是我不确定如何访问此 TableViewController 以便进行自定义。
示例:
您可以尝试类似下面的代码。尝试将 topViewController 的 moreNavigationController 视图作为 UITableView 并将自定义 UITableViewDelegate 设置为它。在委托中,您可以覆盖 WillDisplay 单元格函数来自定义单元格。
class ViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
if let moreListViewController = self.moreNavigationController.topViewController {
if let moreListTableView = moreListViewController.view as? UITableView {
moreListTableView.delegate = self
}
}
}
}
extension ViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.backgroundColor = UIColor.random
}
}
private extension UIColor {
static var random: UIColor {
return .init(hue: .random(in: 0...1), saturation: 1, brightness: 1, alpha: 1)
}
}