是否可以自定义 UITableView 中的部分索引列表(例如字体)? [英] Is it possible to customise the section index list in a UITableView (such as font)?

查看:53
本文介绍了是否可以自定义 UITableView 中的部分索引列表(例如字体)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UITableView 使您能够使用诸如

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 }

是否可以通过其他方式对其进行编辑?正在寻找 Swift 实现.

Is it possible to edit it in other ways? Looking for Swift implementations.

推荐答案

如果您可以访问私有属性,则可以对其进行调整.我相信这会通过商店的批准,但不要相信我的话.以下是您可以访问的属性/功能.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()
        }
    }
}

这篇关于是否可以自定义 UITableView 中的部分索引列表(例如字体)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆