How do I change the color of the side Alphabet in an indexed UITableView?

后端 未结 12 965
温柔的废话
温柔的废话 2020-11-27 14:03

I have a table view with an alphabetical index and am using the side alphabet to get through the list quickly. For those not familiar, that uses this:

- (NS         


        
12条回答
  •  南笙
    南笙 (楼主)
    2020-11-27 14:28

    Swift edition for undocumented font change:

    extension NSObject {
    
        class func objectClassName() -> String {
    
            let classLongName = reflect(self.self).summary;
    
            let tokens = classLongName.componentsSeparatedByString(".")
    
            if let typeName = tokens.last {
    
                return typeName
            }
    
            return NSStringFromClass(self.dynamicType)
        }
    }
    
    func changeSectionIndexFont(tableView: UITableView) -> Void {
    
            let realSubviews = tableView.subviews as! [UIView]
    
            for subview in realSubviews {
    
                if subview.dynamicType.objectClassName() == "UITableViewIndex" {
    
                    subview.setValue(UIFont(name: "OpenSans", size: 10), forKey: "font")
                }
            }
        }
    

提交回复
热议问题