问题
UITableView gives you the ability to edit colors of the section index list with properties such as
var sectionIndexColor: UIColor? { get set }
var sectionIndexBackgroundColor: UIColor? { get set }
Is it possible to edit it in other ways? Looking for Swift implementations.
回答1:
It is possible to adjust it if you're okay with accessing private properties. I believe this would pass store approval but don't take my word for it. Here are the properties/functions you would be able to access. https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/UIKit.framework/UITableViewIndex.h
I've tested changing the font with the following and it worked.
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()
}
}
}
来源:https://stackoverflow.com/questions/45833132/is-it-possible-to-customise-the-section-index-list-in-a-uitableview-such-as-fon