Swift   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了《 Swift UITabBarController 的使用和自定义TabBar,和部分属性和代理的使用》大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

/*      《 Swift  UITabBarController 的使用和自定义TabBar,和部分属性和代理的使用》 */ /*     标签栏控制器是当前市场App的主流架构方式。它主要是用来控制视图控制器的。它所管理的控制器,都是独立的。 */ //  Created by 周双建 on 15/12/8. //  Copyright © 2015年 周双建. All rights re


/*

Swift UITabBarController 的使用和自定义TabBar,和部分属性和代理的使用》

*/

/*

标签栏控制器是当前市场App的主流架构方式。它主要是用来控制视图控制器的。它所管理的控制器,都是独立的。

// Created by 周双建 on 15/12/8.

// Copyright © 2015 周双建. All rights reserved.

//


import UIKit


@UIApplicationMain

class AppDelegate: UIResponder,UIApplicationDelegate,UITabBarControllerDelegate {


var window: UIWindow?



func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

// 标签栏控制器,向导航栏一样,要在 AppDelegate 里面创建

let tabbar_zsj = UITabBarController()

//创建三个视图控制器

/**********************************************************/

//第@L_944_4@

let VC1 = ViewController()

//单个设置属性

var image = UIImage(named:"ic_nav_dis")

//保留原图信息,否则,图片会被纯色代替

image=image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)

//设置没有选中的图片

VC1.tabBarItem.image = image

//设置标题

VC1.tabBarItem.title = "成功"

//选中时的图片

var image_s = UIImage(named: "ic_nav_dis_s")

//保留原图信息,以防纯色代替

image_s = image_s?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)

VC1.tabBarItem.SELEctedImage = image_s

/**********************************************************/


//第二个

let VC2 = TwoViewController()

// 设置选中与未选中的图片

var image_v2 = UIImage(named: "ic_nav_home")

//保色

image_v2 = image_v2?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)

var image_v2_s = UIImage(named: "ic_nav_home_s")

//保色

image_v2_s = image_v2_s?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)

//创建@L_944_4@tabbaritem

let zsj_tababr = UITabBarItem(title: "奋斗",image: image_v2,SELEctedImage: image_v2_s)

VC2.tabBarItem = zsj_tababr

第三个

let VC3 = ThreeViewController()

// 使用系统的方法创建

var image_v3 = UIImage(named: "ic_nav_try_on")

// image_v3 = image_v3?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)

//使用系统图标创建@L_944_4@tabbaritem的对象

let zsj_tabbarV3 = UITabBarItem(tabBarSystemItem: UITabBarSystemItem.Downloads,tag: 100)

zsj_tabbarV3.image = image_v3

zsj_tabbarV3.title = "勤勉"

VC3.tabBarItem = zsj_tabbarV3

/**********************************************************/

//设置标签栏的其他属性

// 第一种 代理

tabbar_zsj.delegate = self

/**********************************************************/

//设置开始选中那个控制器

tabbar_zsj.SELEctedIndex = 1

// 标签 的设置

VC2.tabBarItem.badgeValue = "100+"

/**********************************************************/


// 将三个标签添加标签栏控制器

tabbar_zsj.viewControllers = [VC1,VC2,VC3]

//这个方法,必须在,所有的标签都设置到tabbar 上才可以设置,否则报错

tabbar_zsj.SELEctedViewController = VC2

/*

错误是:eason: '-[UITabBarController setSELEctedViewController:] only a view controller in the tab bar controller's list of view controllers can be SELEcted.

*/

//添加widows 上面进行显示

self.window?.rootViewController = tabbar_zsj

// Override point for customization after application launch.

return true

}

/******************************************************************/

//实现其 tabbar控制器的几种协议方法

/*

UITabBarControllerDelegate 的这个方法,用于返回@L_944_4@负责管理过渡动画的 UIViewControllerAnimatedTransitioning

*/

func tabBarController(tabBarController: UITabBarController,animationControllerForTransitionFromViewController fromVC: UIViewController,toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {

// 下面会给出TransitioningObject的实现,这里我们可以也可以选择用本方法fromVCtoVCtabBarController这三个参数构造出@L_944_4@TransitioningObject

return nil

}

/* // 另@L_944_4@新东西就是 UIViewControllerAnimatedTransitioning 自己。。。有两个方法需要实现

// 这个方法负责做真正的动画,输入参数是过渡的上下文,从哪个VC过渡到哪个VC这些东西都可以从它得到。

func animateTransition(_ transitionContext: UIViewControllerContextTransitioning)

// 这个返回本过渡的持续时间

func transitionDuration(_ transitionContext:

UIViewControllerContextTransitioning) -> NSTimeInterval

/***************************************************/

//监控你选着的是哪个 控制器

func tabBarController(tabBarController: UITabBarController,didSELEctViewController viewController: UIViewController) {

print(viewController)

}

/****************************************************************/

func tabBarController(tabBarController: UITabBarController,shouldSELEctViewController viewController: UIViewController) -> Bool {

//标签栏是否可以选着 TRUE 可选 flase 不可

if viewController.isKindOfClass(TwoViewController){

return false

}else{

return true

}

}

/***************************************************************/

// 开始编辑,标签栏的时候调用

func tabBarController(tabBarController: UITabBarController,willBeginCustomizingViewControllers viewControllers: [UIViewController]) {

}

/*************************************************************/

func tabBarController(tabBarController: UITabBarController,willEndCustomizingViewControllers viewControllers: [UIViewController],changed: Bool) {

//将要结束标签栏的,编辑

}

/***************************************************************/

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 throttle down OpenGL ES frame rates. 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 inactive 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:.

}



}

大佬总结

以上是大佬教程为你收集整理的《 Swift UITabBarController 的使用和自定义TabBar,和部分属性和代理的使用》全部内容,希望文章能够帮你解决《 Swift UITabBarController 的使用和自定义TabBar,和部分属性和代理的使用》所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。