Swift Tabbar的使用
在 Swift 中使用 UITabBarController 来创建一个具有选项卡界面的应用程序。下面是一个简单的示例,演示如何在 Swift 中使用 UITabBarController:
import UIKitclass RootTabbar: UITabBarController {override func viewDidLoad() {super.viewDidLoad()let nav1 = UINavigationController(rootViewController: ControlMainController())let nav2 = UINavigationController(rootViewController: BusinessMainController())let nav3 = UINavigationController(rootViewController: OtherMainClassController())//设置tabBaritem的标题nav1.tabBarItem.title = "控件"nav2.tabBarItem.title = "业务"nav3.tabBarItem.title = "其他"//设置tabBaritem的普通状态的图标nav1.tabBarItem.image = UIImage(named:"tabbar_1")nav2.tabBarItem.image = UIImage(named:"tabbar_2")nav3.tabBarItem.image = UIImage(named:"tabbar_3")//设置tabBaritem选中的图标nav1.tabBarItem.selectedImage = UIImage(named: "tabbar_1a")?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal)nav2.tabBarItem.selectedImage = UIImage(named: "tabbar_2a")?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal)nav3.tabBarItem.selectedImage = UIImage(named: "tabbar_3a")?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal)//设置tabBaritem的标题文字颜色self.tabBar.tintColor = UIColor.COLOR(r: 87, g: 173, b: 57)self.viewControllers = [nav1, nav2, nav3]}
}