swift-UINavigationController纯代码自定义导航控制器及底部工具栏的使用
step1:自定义一个类 NTViewController,该类继承UITabBarController:
//
// NTViewController.swift
// Housekeeper
//
// Created by 卢洋 on 15/10/20.
// Copyright © 2015年 奈文摩尔. All rights reserved.
// import Foundation
import UIKit
class NTViewController:UITabBarController{ var items=[];
//页面初始化
override func viewDidLoad() {
super.viewDidLoad();
//1.创建首页导航控制器
let vwIndex=index();
let navIndex=UINavigationController(rootViewController: vwIndex);
navIndex.title="首页";
//设置工具栏默认显示的图片
navIndex.tabBarItem.image=UIImage(named: "home")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
//设置工具栏选中后的图片
navIndex.tabBarItem.selectedImage=UIImage(named: "homes.png")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); //2.创建活动信息导航控制器
let vwActivityInfo=activityInfo();
let navActivityInfo=UINavigationController(rootViewController: vwActivityInfo);
navActivityInfo.title="活动信息";
navActivityInfo.tabBarItem.image=UIImage(named: "Activity-information.png")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
navActivityInfo.tabBarItem.selectedImage=UIImage(named: "Activity-informations.png")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); //3.创建车辆展示导航控制器
let vwCarDisplay=carDisplay();
let navCarDisplay=UINavigationController(rootViewController: vwCarDisplay);
navCarDisplay.title="车辆展示";
navCarDisplay.tabBarItem.image=UIImage(named: "Vehicle-display.png")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
navCarDisplay.tabBarItem.selectedImage=UIImage(named: "Vehicle-displays.png")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); //4.创建个人中心导航控制器
let vwPersonalCenter=personalCenter();
let navPersonalCenter=UINavigationController(rootViewController: vwPersonalCenter);
navPersonalCenter.title="个人中心";
navPersonalCenter.tabBarItem.image=UIImage(named: "Personal-Center.png")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
navPersonalCenter.tabBarItem.selectedImage=UIImage(named: "Personal-Centers.png")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); //5.添加到工具栏
items=[navIndex,navActivityInfo,navCarDisplay,navPersonalCenter];
self.viewControllers=items as? [UIViewController];
self.navigationController?.navigationBar.tintColor=UIColor.whiteColor(); //6.自定义工具栏
self.tabBar.backgroundColor=UIColor.clearColor();
//底部工具栏背景颜色
self.tabBar.barTintColor=UIColor.appMainColor(); //7.设置底部工具栏文字颜色(默认状态和选中状态)
UITabBarItem.appearance().setTitleTextAttributes(NSDictionary(object:UIColor.whiteColor(), forKey:NSForegroundColorAttributeName) as? [String : AnyObject], forState:UIControlState.Normal);
UITabBarItem.appearance().setTitleTextAttributes(NSDictionary(object:UIColor.blueWithTabbar(), forKey:NSForegroundColorAttributeName) as? [String : AnyObject], forState:UIControlState.Selected) } }
step2:打开 AppDelegate.swift
//
// AppDelegate.swift
// Housekeeper
//
// Created by 卢洋 on 15/10/14.
// Copyright © 2015年 奈文摩尔. All rights reserved.
// import Foundation
import UIKit @UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// 应用程序启动后
//1.声明一个空视图
self.window = UIWindow(frame: UIScreen.mainScreen().bounds);
self.window!.backgroundColor=UIColor.whiteColor(); //2.1导航背景颜色
UINavigationBar.appearance().barTintColor=UIColor.appMainColor(); UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(CGFloat(NSInteger.min),CGFloat(NSInteger.min)), forBarMetrics:UIBarMetrics.Default);
//2.2导航标题文字颜色
UINavigationBar.appearance().titleTextAttributes=NSDictionary(object:UIColor.whiteColor(), forKey:NSForegroundColorAttributeName) as? [String : AnyObject];
//楼主的状态栏颜色改变了,设置为了白色,如果有需要,打开 info.plist 增加Key(View controller-based status bar appearance,Value为 no
//2.3将状态栏变为白色
UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent; //2.4设置返回按钮颜色
UINavigationBar.appearance().tintColor=UIColor.whiteColor(); //3.指定根视图
let rootView=NTViewController();
self.window!.rootViewController=rootView;
self.window!.makeKeyAndVisible(); 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 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-UINavigationController纯代码自定义导航控制器及底部工具栏的使用的更多相关文章
- swift UITabelVIew - 纯代码自定义tabelViewCell
// // CustomTableViewCell.swift // tab // // Created by su on 15/12/7. // Copyright © 2015年 tian ...
- AJ学IOS 之微博项目实战(2)微博主框架-自定义导航控制器NavigationController
AJ分享,必须精品 一:添加导航控制器 上一篇博客完成了对底部的TabBar的设置,这一章我们完成自定义导航控制器(NYNavigationController). 为啥要做自定义呢,因为为了更好地封 ...
- ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布局
本文转自 :http://www.cnblogs.com/wendingding/p/3761730.html ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布 ...
- iOS彩票项目--第一天,自定义TabBar控制器和自定义TabBar,自定义导航控制器
一.环境配置,和项目层次搭建 二.自定义TabBar 项目中TabBar中的导航按钮美工给的图片太大,图片中包含了图片和文字.最主要的是TabBar上面的按钮图片尺寸是有规定的,当高度大于44的时候, ...
- iOS开发小技巧--纯代码自定义cell
纯代码自定义cell 自定义cell的步骤(每个cell的高度不一样,每个cell里面显示的内容也不一样) 1.新建一个继承自UITableViewCell的子类 2.在initWithStyle:方 ...
- IOS开发之——自定义导航控制器
BasicNavigationViewController:UINavigationViwController /* 隐藏导航底部线条 */ -(void)viewDidLoad{ [super ...
- IOS开发之功能模块--自定义导航控制器类常用自定义的代码
前言:本文篇幅不多,但是涉及到的内容却是开发中常用的. 涉及的内容: 1.统一设置导航控制器子控制器的返回按钮. 2.因为修改了系统的返回按钮,所以还需要设置手势事件. 3.隐藏底部的工具条. 这里直 ...
- swift 之 纯代码创建 cell
初学swift 但是网上只有很多swift用xib创建的cell,就算是有也不是我想要的.今天自己弄了一个不用xib纯代码写的,来上代码 博客地址: https://github.com/liguol ...
- AJ学IOS(17)UI之纯代码自定义Cell实现新浪微博UI
AJ分享,必须精品 先看效果图 编程思路 代码创建Cell的步骤 1> 创建自定义Cell,继承自UITableViewCell 2> 根据需求,确定控件,并定义属性 3> 用get ...
随机推荐
- 从打击App刷榜看苹果的底线
这两天苹果打击App刷榜者的消息刷屏了,从腾讯科技.appying多个媒体渠道看到,<安居客>.<友秘>.<微在>.<秦时明月2>.<悟空与貂蝉& ...
- WingIDE 5.0注冊机
在wingIDE下开发python很方便,但IDE不是免费的,网上有破解的方法.请支持正版. 把下列文件CalcActivationCode.py载入到wingIDE中.LicenseID能够随便给一 ...
- ios method swizzling
阅读器 iOS开发iOS 本文由TracyYih[博客]翻译自NSHipster的文章Method Swizzling. 在上周associated objects一文中,我们开始探索Ob ...
- Java代码规范_插件_阿里java开发手册
给大家分享一个阿里巴巴的java开发规范,在日常自动化工作中我们可以参考一下,特别是用java进行coding的同学. 而且还可以利用相应的插件进行代码扫描检测,感兴趣的们可以马上应用到自动化中来. ...
- xshell暂停串口的打印【转】
本文转载自:http://www.360doc.com/content/16/0311/10/7821691_541261680.shtml xshell不想CRT可以断开而停止打印,看这停下的打印信 ...
- Java 下的函数对象
1. 举例 如我们要创建一个对大小写敏感的,按照字母序排序的 Set,我们需要向 Set 的构造器传入 String.CASE_INSENTIVE_ORDER 的比较器: Set<String& ...
- springAOP注解方式定义切入点报错error at ::0 can't find referenced pointcut
[说明] 1.使用spring版本:4.0.4 2.springAOP相关依赖包: 1)aopalliance-1.0.jar 2)aspectjweaver-1.8.9.jar 3)aspectjr ...
- Sara Cope关于text-shadow的介绍
作者:Sara Cope p { text-shadow: 1px 1px 1px #000; } 你可以通过逗号“,”应用多个文本阴影. p { text-shadow: 1px 1px 1px # ...
- Akka源码分析-Remote-网络链接生命周期
remote模式下,网络链接的生命周期往往影响着对应Actor的生命周期,那么网络链接的生命周期是怎么样的呢? 每一个与远程系统的链路都是四个状态之一:空闲.活跃.被守护.被隔离.远程系统的某个地址没 ...
- akka设计模式系列-Chain模式
链式调用在很多框架和系统中经常存在,算不得上是我自己总结的设计模式,此处只是简单介绍在Akka中的两种实现方式.我在这边博客中简化了链式调用的场景,简化后也更符合Akka的设计哲学. trait Ch ...