终于效果图:

Main.storyboard

初始化的控制器是:导航控制器

它的根控制器是:TabBarController

TabBarController的底部是一个自己定义的TabBar

里面加入了5个TabBarItem

点击每个item,

会将tabBar上的相应item的子控制器的navigationItem的值,

转移(赋值,复制)给TabBarController的navigationItem,

从而显示在导航栏上,

由于TabBarController就是导航控制器的根控制器,也同一时候就是栈顶控制器,导航控制器仅仅知道它的存在

//
// BeyondTabBarController.m
// 25_彩票
//
// Created by beyond on 14-8-27.
// Copyright (c) 2014年 com.beyond. All rights reserved.
// #import "BeyondTabBarController.h"
#import "BeyondTabBar.h"
#import "BeyondTabBarItem.h"
#import "BeyondTabBarDelegate.h"
@interface BeyondTabBarController ()<BeyondTabBarDelegate> @end @implementation BeyondTabBarController - (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated]; static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// 1.釜底抽薪 直接删除默认的tabBar
[self.tabBar removeFromSuperview]; // 2.创建tabbar
BeyondTabBar *myTabBar = [[BeyondTabBar alloc] init];
// 占位原来的tabBar
myTabBar.frame = self.tabBar.frame;
// 代理设置后,能够接收tabBar内部button的点击状态切换
myTabBar.delegate = self;
// 加入到当前控制器的view
[self.view addSubview:myTabBar]; // 3.由于 图片名的规律性,一次性加入5个tabBarItembutton
for (int i = 1; i<=5; i++) {
NSString *normal = [NSString stringWithFormat:@"TabBar%d", i];
NSString *selected = [normal stringByAppendingString:@"Sel"];
// 调用tabBar开放出来的接口,向tabBar内部加入button,仅仅要传參:图片名
[myTabBar addOneTabBarItem:normal selectedIconName:selected];
}
});
} #pragma mark - tabbar代理方法
- (void)tabBar:(BeyondTabBarItem *)tabBar didSelectButtonFrom:(NSUInteger)from to:(NSUInteger)to
{
// 1.直接通过索引 选中某个控制器(这个是UITabBarController自带的API)
self.selectedIndex = to; UITableViewController *newVC = self.childViewControllers[to];
// 2.将tabBar上的相应button的子控制器的navigationItem值转移给TabBarController,由于导航控制器的根控制器就是TabBarController,导航控制器 仅仅知道它的存在
[self.navigationItem copyFromItem:newVC.navigationItem];
}@end

导航栏的适配

仅仅需提供64高和44高的背景图片就可以

//
// BeyondNavigationController.m
// 25_彩票
//
// Created by beyond on 14-8-27.
// Copyright (c) 2014年 com.beyond. All rights reserved.
// #import "BeyondNavigationController.h" @interface BeyondNavigationController () @end @implementation BeyondNavigationController #pragma mark 一个类仅仅会调用一次
+ (void)initialize
{
// 1.取出设置主题的对象
UINavigationBar *navBar = [UINavigationBar appearance];
UIBarButtonItem *barItem = [UIBarButtonItem appearance]; // 2.设置导航栏的背景图片
NSString *navBarBg = nil;
// 推断iOS7
// [[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0
if (iOS7) {
// 使用64高度的图片,做导航栏背景图片
navBarBg = @"NavBar64";
// 设置导航栏的渐变色为白色(iOS7中返回箭头的颜色变为这个颜色:白色)
navBar.tintColor = [UIColor whiteColor];
} else {
// 非iOS7,使用44高度的图片
navBarBg = @"NavBar";
// 黑色的顶部状态条
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
// 设置导航栏button的背景图片
[barItem setBgImgForNormal:@"NavButton" highlighted:@"NavButtonPressed"]; // 设置导航栏返回button的背景图片
[barItem setBackBtnBgImgForNormal:@"NavBackButton" highlighted:@"NavBackButtonPressed"];
} [navBar setBackgroundImage:[UIImage imageNamed:navBarBg] forBarMetrics:UIBarMetricsDefault]; // 3.设置导航栏标题颜色为白色
[navBar setTitleTextAttributes:@{
NSForegroundColorAttributeName : [UIColor whiteColor]
}]; // 4.设置导航栏button文字颜色为白色
[barItem setTitleTextAttributes:@{
NSForegroundColorAttributeName : [UIColor whiteColor],
NSFontAttributeName : [UIFont systemFontOfSize:13]
} forState:UIControlStateNormal];
} #pragma mark 控制状态栏的样式
/*
状态栏的管理:
1> iOS7之前:UIApplication
2> iOS7開始:交给相应的控制器去管理
*/
- (UIStatusBarStyle)preferredStatusBarStyle
{
// 白色样式
return UIStatusBarStyleLightContent;
} @end

iOS_25_彩票骨架搭建+导航栏适配的更多相关文章

  1. ios导航栏适配

    我们做屏幕导航栏横竖屏适配的时候,会发现top的值多少都有一点的偏移,加了背景色之后从0开始,不加背景色从64开始,解决方法self.extendedLayoutIncludesOpaqueBars ...

  2. ios7 导航栏适配

    ios ui开发过程中,经常会使用到导航栏,默认的样式比较单一,所以经常需要修改导航栏的样式 ios4: - (void)drawRect:(CGRect)rect { UIImage *image ...

  3. IOS7 导航栏适配二

    ios7下的app都是全屏的,意思就是所有控制器的view默认都是从  屏幕的 (0,0)开始. 这时候用到导航栏时,往往会出现被导航栏挡住情况. 最明显的是用到tableView时,第一行的数据会被 ...

  4. iOS10 的适配问题,你遇到了吗?导航栏标题和返回按钮神奇的消失了

    苹果系统升级后好多应用都发了新版本来适配,今天就来分享一下我的适配历程. 首先是出现的问题: 1.push一个控制器,返回按钮和标题神奇的消失了,打开三维视图(比较坑的是有的版本老到打不开三维视图 ) ...

  5. IOS7 适配时导航栏变黑

    当适配IOS的布局时遇到问题:导航栏和菜单栏后台会变黑色. self.edgesForExtendedLayout = UIRectEdgeNone; 原因是系统默认这两个控件是半通明的. 解决方案: ...

  6. 使用bootstrap3.0搭建一个具有自定义风格的侧边导航栏

    由于工作变动,新的项目组,可能会涉及到更多的类似于后台管理系统这一类的项目,而且开发可能更加偏向于传统型的开发,希望今后能够在新的项目中能够用得上vuejs吧! 接手项目的时候,就是一个后台管理系统, ...

  7. ios开发之--iOS 11适配:iOS11导航栏返回偏移

    UIBarButtonItem 左边间隙过大,解决方案(ios11之前): 调用下面的方法,设置negativeSpacer.width = -15;就可以解决间隙过大的问题: UIBarButton ...

  8. 微信小程序自定义导航栏组件,完美适配所有手机,可实现各种功能和情况

    背景 在做小程序时,关于默认导航栏,我们遇到了以下的问题: Android.IOS 手机对于页面 title 的展示不一致,安卓 title 的显示不居中 页面的 title 只支持纯文本级别的样式控 ...

  9. 使用webpack从0搭建多入口网站脚手架,可复用导航栏/底部通栏/侧边栏,根据页面文件自动更改配置,支持ES6/Less

    之前只知道webpack很强大,但是一直没有深入学习过,这次从头看了一下教程,然后从0开始搭建了一个多入口网站的开发脚手架,期间遇到过很多问题,所以有心整理一下,希望能给大家一点帮助. 多HTML网站 ...

随机推荐

  1. 一年的天数 Exercise06_16

    /** * @author 冰樱梦 * 时间:2018年下半年 * 题目:一年的天数 * */ public class Exercise06_16 { public static void main ...

  2. cocos2d-x引擎优化 修改记录

    3.13 一些无聊的bug etc1 在android 平台不能正常显示,包括 cc.Button,setGray,clipeNode     3.13.1优化记录   7月 2.公式计算改为长整型, ...

  3. 【MySQL笔记】: unable to connect to remote host. catalog download has failed.

    安装完MySQL之后,它每天凌晨启动一个Intaller任务,甚是烦人:   这是一个Windows的计划服务,在这里删除即可,开始/附件/系统工具/任务计划程序,把mysql的定时任务计划取消/删除 ...

  4. 触摸事件onTouchListener

    1.效果图: (1)MainAcivity.java package com.example.app3; import android.content.DialogInterface; import ...

  5. Saga的实现模式——观察者(Saga implementation patterns – Observer)

    https://lostechies.com/jimmybogard/2013/03/11/saga-implementation-patterns-observer/ 侵删. NServiceBus ...

  6. redis push/pop(List)的17条命令

    一.Blpop 命令移出并获取列表的第一个元素, 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止.redis 127.0.0.1:6379> BLPOP LIST1 LIST2 .. ...

  7. HTC VIVE SDK 中的例子 hellovr_opengl 程序流程分析

    最近Vive的VR头盔设备很火,恰逢项目需求,所以对 SDK 中的例子 hellovr_opengl 做了比较细致的代码分析,先将流程图绘制如下,便于大家理解. 在ViVe头盔中实现立体效果的技术核心 ...

  8. 在Centos 7中使用 Docker搭建MySQL异地双向复制环境

    (0)一些准备操作: Centos安装好之后(这里使用的是vm虚拟机) 将当前用户添加到sudoers中: su root vim /etc/sudoers 找到 root ALL=(ALL) ALL ...

  9. Docker解析及轻量级PaaS平台演练(二)--Docker的一些简单命令

    上一篇中,我们对Docker有了一个基本的了解 下面将讨论Docker中Image,Container的相关实际操作 Image管理: 镜像的命名和版本管理: 普通镜像的命名规范 {namespace ...

  10. vue2 router-link to

    <template> <div> <nv-header></nv-header> <div class="artlist"&g ...