7.1、初识UITabbar

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

// App底部的tab标签页可以方便的把功能模块划分清楚,只需点击相应的标签页就可以展示完全独立的视图页面,同时各标签页间的视图也可以进行数据交换
let tabbarVC = UITabBarController()
self.window?.rootViewController = tabbarVC
self.window?.makeKeyAndVisible()

    let one = UIViewController()
    one.view.backgroundColor = UIColor.cyan
    one.tabBarItem.title = "首页"
    one.tabBarItem.tag = 100
    one.tabBarItem.image = UIImage(named: "tabbar01_normal")
    one.tabBarItem.selectedImage = UIImage(named: "tabbar01_selected")?.withRenderingMode(.alwaysOriginal)
    
    let two = UIViewController()
    two.view.backgroundColor = UIColor.red
    two.tabBarItem.title = "我的"
    two.tabBarItem.tag = 101
    two.tabBarItem.image = UIImage(named: "tabbar02_normal")
    two.tabBarItem.selectedImage = UIImage(named: "tabbar02_selected")?.withRenderingMode(.alwaysOriginal)
    
    tabbarVC.viewControllers = [one,two]
    tabbarVC.tabBar.isTranslucent = false
    tabbarVC.tabBar.tintColor = UIColor.yellow
    return true
}

func applicationWillResignActive(_ application: UIApplication) {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 我很想问大家:当我们吃的越来越精致,是前进了还是倒退? 我其实很喜欢精致,因为用心,但生活要回到本源,所以现在更喜...
    木月生阅读 2,311评论 0 3
  • 母亲去世之前的几年,诊断和治疗都是她的女婿把关的。我哥哥说,我妈能多活那几年都是我妹夫(医术精湛)的功劳...
    小石子兒阅读 374评论 0 0
  • 我是共振之月,第三周耐心使行動改變, 第17天出生 共振之月对应的问题,我如何调整自己以更多地服務他人 蓝色蛻変之...
    eleensharda203阅读 203评论 0 0

友情链接更多精彩内容