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 ...
随机推荐
- 表格属就用treegrid
http://maxazan.github.io/jquery-treegrid/ 如果想ajax后台动态添加表格数据然后再形成treegrid,那么可以通过后台给一个对应行索引的数组, 进行动态改变 ...
- A new Graph Game
点击打开链接 题意:给你一张N个节点的无向图.然后给出M条边,给出第 I 条边到第J条边的距离.然后问你是否存在子环,假设存在,则输出最成环的最短距离和 解析:构图:选定源点及汇点,然后将源点至个点流 ...
- LeetCode 725. Split Linked List in Parts (分裂链表)
Given a (singly) linked list with head node root, write a function to split the linked list into k c ...
- web的自己主动化公布
</pre>基于眼下业务的版本号.使用的maven 及tomcat <p></p><p>假设我们使用 Jenkins 公布是比較好的,可是存在一定的问题 ...
- CA certificate
1 什么是CA certificate CA证书本质上是一把公钥. 2 为什么需要CA证书 是为了避免黑客冒充服务器,服务器通过CA证书证明自己是真的服务器,而不是黑客. 就是说,一旦客户端有了一个服 ...
- hbase查询_Phoenix及hbase repl命令行两种方式
一.Phoenix(jdbc)登陆 1.cd /home/mr/phoenix/bin(此路径每个环境里面有可能不一样)2../sqlline.py localhost 二.shell repl Hb ...
- 【BZOJ 3032】 七夕祭
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3032 [算法] 交换左右两个相邻格子的摊点,不会改变这一行的摊点个数 交换上下两个相 ...
- 搭建Git服务器(转载)
转自:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137583770360 ...
- Akka源码分析-Remote-网络链接生命周期
remote模式下,网络链接的生命周期往往影响着对应Actor的生命周期,那么网络链接的生命周期是怎么样的呢? 每一个与远程系统的链路都是四个状态之一:空闲.活跃.被守护.被隔离.远程系统的某个地址没 ...
- pip使用豆瓣镜像源
pip使用豆瓣的镜像源 豆瓣镜像地址: https://pypi.douban.com/simple/ 虽然用easy_install和pip来安装第三方库很方便 他们的原理其实就是从Python的官 ...