Swift 标签栏的设置

设置标签栏

private func creatNavigationController(dict: [String: AnyObject]) -> DTNavigationController{
    guard  let className       = dict["className"] as? String,
           let title           = dict["title"] as? String,
           let imageName       = dict["imageName"] as? String,
           let selectImageName = dict["selectImageName"] as? String,
           let cls = NSClassFromString(Bundle.main.namespace + "." + className) as? DTViewController.Type
        else {
        return DTNavigationController()
    }
    let vc = cls.init()
    vc.title = title
    vc.tabBarItem.image            = UIImage(named: imageName)
    vc.tabBarItem.selectedImage    = UIImage(named: selectImageName)?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)//使用图片原来颜色
    let attributes                 = [NSForegroundColorAttributeName :UIColor.black,
                                      NSFontAttributeName: UIFont(name: "Heiti SC", size: 12)!]
    let selattributes              = [NSForegroundColorAttributeName :UIColor(red: 251.0/255.0, green: 0, blue: 77.0/255.0, alpha: 1),
                                      NSFontAttributeName: UIFont(name: "Heiti SC", size: 12)!]
    vc.tabBarItem.setTitleTextAttributes(attributes , for: UIControlState.normal)
    vc.tabBarItem.setTitleTextAttributes(selattributes , for: UIControlState.selected)
    let uNC                        = DTNavigationController(rootViewController: vc)

    return uNC
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容