自定义TabBarController
有时候默认的TabBarController不能满足我们的开发需求,比如你想用彩色的图标,系统却只调用图标的轮廓,所以我们需要自己定义一下TabBar。
方法一:修改TabBarController中的TabBar
新建 CustomTabBarController 类继承自 UITabBarController,并在Storyboard中设置:
首先自定义 tabBar 的背景,在 viewDidLoad() 方法中添加:
// 声明新的无标题TabBarItem
let tabBarItem = UITabBarItem(title: nil, image: image, selectedImage: selectedImage)
// 设置 tabBarItem 的 imageInsets 可以使图标居中显示
tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0)
viewController.tabBarItem = tabBarItem
}
本文地址:https://www.stayed.cn/item/7443
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我