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纯代码自定义导航控制器及底部工具栏的使用的更多相关文章

  1. swift UITabelVIew - 纯代码自定义tabelViewCell

    // //  CustomTableViewCell.swift //  tab // //  Created by su on 15/12/7. //  Copyright © 2015年 tian ...

  2. AJ学IOS 之微博项目实战(2)微博主框架-自定义导航控制器NavigationController

    AJ分享,必须精品 一:添加导航控制器 上一篇博客完成了对底部的TabBar的设置,这一章我们完成自定义导航控制器(NYNavigationController). 为啥要做自定义呢,因为为了更好地封 ...

  3. ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布局

    本文转自 :http://www.cnblogs.com/wendingding/p/3761730.html ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布 ...

  4. iOS彩票项目--第一天,自定义TabBar控制器和自定义TabBar,自定义导航控制器

    一.环境配置,和项目层次搭建 二.自定义TabBar 项目中TabBar中的导航按钮美工给的图片太大,图片中包含了图片和文字.最主要的是TabBar上面的按钮图片尺寸是有规定的,当高度大于44的时候, ...

  5. iOS开发小技巧--纯代码自定义cell

    纯代码自定义cell 自定义cell的步骤(每个cell的高度不一样,每个cell里面显示的内容也不一样) 1.新建一个继承自UITableViewCell的子类 2.在initWithStyle:方 ...

  6. IOS开发之——自定义导航控制器

    BasicNavigationViewController:UINavigationViwController /* 隐藏导航底部线条 */ -(void)viewDidLoad{    [super ...

  7. IOS开发之功能模块--自定义导航控制器类常用自定义的代码

    前言:本文篇幅不多,但是涉及到的内容却是开发中常用的. 涉及的内容: 1.统一设置导航控制器子控制器的返回按钮. 2.因为修改了系统的返回按钮,所以还需要设置手势事件. 3.隐藏底部的工具条. 这里直 ...

  8. swift 之 纯代码创建 cell

    初学swift 但是网上只有很多swift用xib创建的cell,就算是有也不是我想要的.今天自己弄了一个不用xib纯代码写的,来上代码 博客地址: https://github.com/liguol ...

  9. AJ学IOS(17)UI之纯代码自定义Cell实现新浪微博UI

    AJ分享,必须精品 先看效果图 编程思路 代码创建Cell的步骤 1> 创建自定义Cell,继承自UITableViewCell 2> 根据需求,确定控件,并定义属性 3> 用get ...

随机推荐

  1. hive学习笔记-表操作

    Hive数据类型 基本数据类型 tinyint,smallint,int,biging,float,double,decimal,char,varchar,string,binary,boolean, ...

  2. javaScript 检測 能否够连接指定server

    本文主要讲述怎样在js里面从多个服务端servlet中找到可用的地址 一般项目部署到生产环境之后会有一个生产网段(就是你能够在家訪问)和一个办公网段(仅仅能在公司才干訪问). 我们的项目部署好了之后, ...

  3. java中不能使用小数点(.)来作为分隔符

    split()括号里是一个String的参数,所以一定要符合这种:split(".")形式,即点'.'要用双引号""括起来"."在java中 ...

  4. MongoDB集群——副本集

    1. 副本集的结构及原理 副本集包括三种节点:主节点.从节点.仲裁节点.主节点负责处理客户端请求,读.写数据, 记录在其上所有操作的oplog: 从节点定期轮询主节点获取这些操作,然后对自己的数据副本 ...

  5. ubuntu安装typora

    optional, but recommended sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BA300B7755AF ...

  6. Ballot evaluation

    http://acm.hdu.edu.cn/showproblem.php?pid=2986 题意很简单,主要是要处理精度,最手残的是把单词拼写错了... #include <stdio.h&g ...

  7. Hotel booking(spfa+floyd)

    http://acm.hdu.edu.cn/showproblem.php?pid=2992 题意:有n个城市,编号为(1~n),有一些城市中有一些旅店,要求从一个城市到另一个城市不能超过10小时,问 ...

  8. Akka源码分析-官方文档说明

    如果有小伙伴在看官方文档的时候,发现有些自相矛盾的地方,不要怀疑,可能是官方文档写错了或写的不清楚,毕竟它只能是把大部分情况描述清楚.开源代码一直在更新,官方文档有没有更新就不知道了,特别是那些官方不 ...

  9. array_column()函数兼容低版本

    array_column 用于获取二维数组中的元素(PHP 5.5新增函数),但我们有时候需要在低版本的 function i_array_column($input, $columnKey, $in ...

  10. An problem about date 根据年月日计算 星期几

    /W = (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7(1.2月需要看作上一年的13.14月) #include<stdio.h> #include& ...