我正在自定义我的 TabBarItems。我通过这样做将 TabBar 的高度更改为我想要的高度:
override func viewWillLayoutSubviews() {
var tabFrame = self.tabBar.frame
tabFrame.size.height = 60
tabFrame.origin.y = self.view.frame.size.height - 60
self.tabBar.frame = tabFrame
}
我想在我的 TabBarItems 上有一个白色背景,如下所示。
但是我很迷茫如何去做,如果可能的话?
最佳答案
您好,我是用 swift 3 写的,您可以将其添加到 appDelegate 文件中
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let tabBarController = window?.rootViewController as! UITabBarController
let image = UIImage(named: "itemBar")
tabBarController.tabBar.backgroundColor = UIColor.white() // 1
tabBarController.tabBar.items?[0].selectedImage = image // 2
return true
}
(1) 你设置tabBar的背景色
(2) 您可以设置所选图像(您可以创建带有那些黑色边框的图像),您可能想为每个不同的项目添加不同的图像,但这是如何对一个项目进行操作的基本示例.
祝你好运
关于ios - 如何自定义TabBarItems?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38131123/