Is it possible to customise the section index list in a UITableView (such as font)?

僤鯓⒐⒋嵵緔 提交于 2019-12-25 19:12:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!