是否可以在UITableView中自定义部分索引列表(例如字体)?



UITableView使您能够使用诸如以下属性编辑节索引列表的颜色

var sectionIndexColor: UIColor? { get set }
var sectionIndexBackgroundColor: UIColor? { get set }

是否可以以其他方式对其进行编辑? 寻找 Swift 实现。

如果您可以访问私有属性,则可以对其进行调整。 我相信这会通过商店的批准,但不要相信我的话。 以下是您可以访问的属性/函数。https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/UIKit.framework/UITableViewIndex.h

我已经测试了使用以下方法更改字体,它奏效了。

func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.async { [unowned self] in
if let tableViewIndex = self.tableView.subviews.first(where: { String(describing: type(of: $0)) == "UITableViewIndex" }) {
tableViewIndex.setValue(*Insert Font Here*, forKey: "font")
self.tableView.reloadSectionIndexTitles()
}
}
}

最新更新