swift|swift 通过plist文件初始化tabbar
【swift|swift 通过plist文件初始化tabbar】使用plist文件来加载控制器以及图片文字等资源
func setup() {
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor(red:56/255.0, green:165/255.0, blue:241/255.0, alpha:1)], forState: .Selected)
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor(red:132/255.0, green:132/255.0, blue:132/255.0, alpha:1)], forState: .Normal)
self.tabBar.backgroundImage = UIImage(named: "tabbar_back")let path = NSBundle.mainBundle().pathForResource("YWTabBarViewController", ofType: "plist")
let array = NSArray(contentsOfFile: path!)if array != nil {
for dic in array! {
//将类名转化为类
//1.获取命名空间
let clsName = NSBundle.mainBundle().infoDictionary!["CFBundleExecutable"] as! Stringlet forDic = dic as! NSDictionary
//2.把字符串形式的类名称转换成类
let classType = NSClassFromString(clsName + "." + "\(forDic["viewController"]!)") as! UIViewController.Type
//3.通过class创建对象
let vc = classType.init()vc.tabBarItem.image = UIImage(named: "\(forDic["image"]!)")
vc.tabBarItem.selectedImage = UIImage(named: "\(forDic["selectImage"]!)")
vc.tabBarItem.title = "\(forDic["title"]!)"
addChildViewController(vc)
}
}}
推荐阅读
- gitlab|gitlab 通过备份还原 admin/runner 500 Internal Server Error
- Swift中willSet和didSet的简述
- Hacking|Hacking with iOS: SwiftUI Edition - SnowSeeker 项目(一)
- LeetCode算法题-11.|LeetCode算法题-11. 盛最多水的容器(Swift)
- whlie循环和for循环的应用
- iOS-Swift-map|iOS-Swift-map filter reduce、函数式编程
- Swift|Swift ----viewController 中addChildViewController
- SwiftUI|SwiftUI iOS 瀑布流组件之仿CollectionView不规则图文混合(教程含源码)
- 如何通过锻炼的方法治疗前列腺肥大
- Swift高级应用|Swift高级应用 -01