且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-12-11 19:06:47

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

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()
        }
    }
}