美文网首页
Swift 标签栏的设置

Swift 标签栏的设置

作者: 七分呗轻唱 | 来源:发表于2016-12-11 12:11 被阅读49次

    设置标签栏

    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
    }

    相关文章

      网友评论

          本文标题:Swift 标签栏的设置

          本文链接:https://www.haomeiwen.com/subject/dqcpmttx.html