一,各种名称和位置

//技巧一键换肤
    [[UINavigationBar appearance]setBarTintColor:[UIColor redColor]];//给所有的NavigationBar换颜色
    [[UITabBar appearance]setBarTintColor:[UIColor blueColor]];//给所有的TabBar换颜色

二,UINavigationBar:

1,设置导航条透明度:self.navigationBar.translucent = NO;

2,设置Bar背景颜色:self.navigationBar.barTintColor = [UIColour RedColour];->The tint color to apply to the navigation bar background.修改bar的背景颜色

3,设置navigation items和bar button items颜色:self.navigationBar.tintColour = [UIColour BlurColour];->The tint color to apply to the navigation items and bar button items.修改navigation items和bar button items;

4,设置返回箭头的自定义图片//imageWithRenderingMode 图片的显示模式,要设置成originnal图片的颜色才会变成自定义的图片颜色,否则默认系统颜色。

UIImage *backImage = [backImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//注意下面两个属性都要设置,只设置一个是无效的。

[UINavigationBar appearance]setBackIndicatorTransitionMaskImage:backimage];

[UINavigationBar appearance]setBackIndicatorImage:backimage];

5,去掉导航栏的文字,钻了空子,设置了文字的PositionAdjustment就可以了:

UIBarButtonItem baritem = [UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class],nil];

UIOffset offset;

offset.horizontal = -500;

[baritem setBackButtonTitlePositionAdjustment:offset forBarMetrics:UIBarMetricsDefault];

typedef NS_ENUM(NSInteger, UIBarMetrics) {UIBarMetricsDefault,//正常竖屏状态UIBarMetricsCompact,//横屏状态
};

6,导航栏文字的设置.

//返回按钮字体属性

[baritem setTitleTextAttributes:@{NSFontAttributeColor:[UIColor RedColor]} forState:UIControlStateNormal];

//改变导航的title样式

NSDictionary *TitleAttributes = [NSDictonary dictionaryWithObjectsAndKeys:Nav_title_Colour,NSForegroundcolourAttributeName,Nav_Titlefont,NSfontAttributeName,nil];

[[UINavigationBar appearance]setTitleTextAttributes:titleAttributes];

Title也是一个Item,TitleView可以将Title换为一个UIView,Title上面可以添加文字:

eg:

- (void)viewDidLoad {[super viewDidLoad];UINavigationItem *item = [[UINavigationItem alloc]initWithTitle:@"Title1"];UINavigationBar *bar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 64)];[[UINavigationBar appearance]setBarTintColor:[UIColor greenColor]];UIView *titleView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];titleView.backgroundColor = [UIColor redColor];item.titleView = titleView;item.prompt = @"标题的介绍";//隐藏返回按钮:hidesBackButton[bar pushNavigationItem:item animated:YES];[self.view addSubview:bar];self.view.backgroundColor = [UIColor grayColor];
}

左右侧的返回按钮可以自己添加设置:

@property(nullable, nonatomic,strong) UIBarButtonItem *leftBarButtonItem;
@property(nullable, nonatomic,strong) UIBarButtonItem *rightBarButtonItem;
- (void)setLeftBarButtonItem:(nullable UIBarButtonItem *)item animated:(BOOL)animated;
- (void)setRightBarButtonItem:(nullable UIBarButtonItem *)item animated:(BOOL)animated;
//添加多个按钮:
@property(nullable,nonatomic,copy) NSArray<UIBarButtonItem *> *leftBarButtonItems;
@property(nullable,nonatomic,copy) NSArray<UIBarButtonItem *> *rightBarButtonItems;
- (void)setLeftBarButtonItems:(nullable NSArray<UIBarButtonItem *> *)items animated:(BOOL)animated;
- (void)setRightBarButtonItems:(nullable NSArray<UIBarButtonItem *> *)items animated:(BOOL)animated;

ButtonItemStyle:

typedef NS_ENUM(NSInteger, UIBarButtonItemStyle) {UIBarButtonItemStylePlain,UIBarButtonItemStyleDone,
};

也可以添加图片创建ButtonItem:

- (instancetype)initWithImage:(nullable UIImage *)image style:(UIBarButtonItemStyle)style target:(nullable id)target action:(nullable SEL)action;
- (instancetype)initWithImage:(nullable UIImage *)image landscapeImagePhone:(nullable UIImage *)landscapeImagePhone style:(UIBarButtonItemStyle)style target:(nullable id)target action:(nullable SEL)action;//landscapeImagePhone style这个参数可以设置设备横屏时的图片//自定义View:
- (instancetype)initWithCustomView:(UIView *)customView;//原生的BarButtonItem:
UIBarButtonItem * button = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:nil];typedef NS_ENUM(NSInteger, UIBarButtonSystemItem) {UIBarButtonSystemItemDone,//显示完成UIBarButtonSystemItemCancel,//显示取消UIBarButtonSystemItemEdit,  //显示编辑UIBarButtonSystemItemSave, //显示保存 UIBarButtonSystemItemAdd,//显示加号UIBarButtonSystemItemFlexibleSpace,//什么都不显示,占位一个空间位置UIBarButtonSystemItemFixedSpace,//和上一个类似UIBarButtonSystemItemCompose,//显示写入按钮UIBarButtonSystemItemReply,//显示循环按钮UIBarButtonSystemItemAction,//显示活动按钮UIBarButtonSystemItemOrganize,//显示组合按钮UIBarButtonSystemItemBookmarks,//显示图书按钮UIBarButtonSystemItemSearch,//显示查找按钮UIBarButtonSystemItemRefresh,//显示刷新按钮UIBarButtonSystemItemStop,//显示停止按钮UIBarButtonSystemItemCamera,//显示相机按钮UIBarButtonSystemItemTrash,//显示移除按钮UIBarButtonSystemItemPlay,//显示播放按钮UIBarButtonSystemItemPause,//显示暂停按钮UIBarButtonSystemItemRewind,//显示退后按钮UIBarButtonSystemItemFastForward,//显示前进按钮UIBarButtonSystemItemUndo,//显示消除按钮UIBarButtonSystemItemRedo ,//显示重做按钮UIBarButtonSystemItemPageCurl ,//在tool上有效
};

7,  UINavigationBar上面不只是简单的显示标题,它也将标题进行了堆栈的管理,每一个标题抽象为的对象在iOS系统中是UINavigationItem对象,我们可以通过push与pop操作管理item组。

//向栈中添加一个item,上一个item会被推向导航栏的左侧,变为pop按钮,会有一个动画效果
- (void)pushNavigationItem:(UINavigationItem *)item animated:(BOOL)animated;
//pop一个item
- (nullable UINavigationItem *)popNavigationItemAnimated:(BOOL)animated;
//当前push到最上层的item
@property(nullable, nonatomic,readonly,strong) UINavigationItem *topItem;
//仅次于最上层的item,一般式被推向导航栏左侧的item
@property(nullable, nonatomic,readonly,strong) UINavigationItem *backItem;
//获取堆栈中所有item的数组
@property(nullable,nonatomic,copy) NSArray<UINavigationItem *> *items;
//设置一组item
- (void)setItems:(nullable NSArray<UINavigationItem *> *)items animated:(BOOL)animated;

8,从一个导航条跳转到另一个导航条,重写系统的Push到下一个页面的方法。

-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{

  if(self.viewController.count > 0){

    //第二层viewController 隐藏tabbar

    ViewController.hidesBottomBarWhenPushed = Yes;

  }

  [super pushViewController:viewController animated:YES];

}

8,修改导航条下面黑线的颜色

[self.navigationController.navigationBar setShadowImage:[UIimage imageWithName:imagecolour];

9,UINavigationBarDelegate

@property(nullable,nonatomic,weak) id<UINavigationBarDelegate> delegate;

通过代理,我们可以监控导航栏的一些push与pop操作:

//item将要push的时候调用,返回NO,则不能push
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPushItem:(UINavigationItem *)item;
//item已经push后调用
- (void)navigationBar:(UINavigationBar *)navigationBar didPushItem:(UINavigationItem *)item;
//item将要pop时调用,返回NO,不能pop
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item;
//item已经pop后调用
- (void)navigationBar:(UINavigationBar *)navigationBar didPopItem:(UINavigationItem *)item;

三,UITabBarController

1,设置背景颜色:self.tabbar.barTintColor = Tab_bar_backcolor;

2,设置标签不透明:self.tabbar.translucent = NO;

3,常规设置:

NSArray classNameArray = [NSArray arrayWithObject:@"firstViewcontroller",@"SecondViewController"@"ThirdViewController",nil];

NSArray titleArray = [NSArray arrayWithObject:@"first",@"Second",@"Third",nil];

NSArray normalImageArray = [NSArray arrayWIthObjects:@"first_normal.png",@"second_normal.png",@"third_normal.png",nil];

NSArray SelectedImageArray = [NSArray arrayWIthObjects:@"first_Selected.png",@"second_Selected.png",@"third_Selected.png",nil];

//添加到Tabbar上

NSMutableArray *navigationArray = [NSMutableArray alloc]init];

for(int i = 0;i<classNameArray.count;i++){

  UIViewController *vc = (UIViewController *)[[NSClassFromString(classNameArray[i])alloc]init;

  vc.title = titleArray[i];

  UIimage *normalImage = [UIImage imageNamed:normalImageArray[i]];

  UIimage *selectedImage = [uiImage imageNamed:selectedImageArray[i]];

  vc.tabBarItem.image =  [normal imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

  vc.taBarItem.selectedImage = [slelectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

}

//去掉标签栏的文字,设置偏移值:

UIOffet offset = [UIOffetMake(0,300);

[vc.tabBarItem setTitlePositionAdjustment:offset];

BaseNavigationViewController na = [[BaseNavigationViewController alloc]initWithRootViewController:vc];

[navigationArray addobject:na];

}

self.viewController = navigationArray;

//标签栏文字设置

UIBaritem item = [UIBarItem appearance];

//正常状态的文字

[item setTitleAttributes:@{NSForegroundColorAttributeName:Tab_color,NSfontAttributeName:Tab-Font} forState:UIControlStateNormal];

//选择的文字

[item setTitleAttributes:@{NSForegroundColorAttributeName:Tab_color_Selected,NSfontAttributeName:Tab-Font_Selected} forState:UIControlStateSelected];

5,修改标签栏下面黑线的颜色

[self.tabBarController.tabbar setShadowImage:[UIimage imageWithName:imagecolour];

三,UIToolBar:(UITabbar的位置,工具条)

UIToolBar一般放在下面:

//工具栏的风格,和导航栏类似,有黑白两种
@property(nonatomic) UIBarStyle barStyle;
//设置工具栏上按钮数组
@property(nullable,nonatomic,copy) NSArray<UIBarButtonItem *> *items;
//设置工具栏是否透明
@property(nonatomic,assign,getter=isTranslucent) BOOL translucent;
//设置工具栏按钮
- (void)setItems:(nullable NSArray<UIBarButtonItem *> *)items animated:(BOOL)animated;
//设置item风格颜色
@property(null_resettable, nonatomic,strong) UIColor *tintColor;
//设置工具栏背景色
@property(nullable, nonatomic,strong) UIColor *barTintColor;
//设置工具栏背景和阴影图案
- (void)setBackgroundImage:(nullable UIImage *)backgroundImage forToolbarPosition:(UIBarPosition)topOrBottom barMetrics:(UIBarMetrics)barMetrics;
- (nullable UIImage *)backgroundImageForToolbarPosition:(UIBarPosition)topOrBottom barMetrics:(UIBarMetrics)barMetrics;
- (void)setShadowImage:(nullable UIImage *)shadowImage forToolbarPosition:(UIBarPosition)topOrBottom;
- (nullable UIImage *)shadowImageForToolbarPosition:(UIBarPosition)topOrBottom;

转载于:https://www.cnblogs.com/yangqinglong/p/5574303.html

UITabBarController+UINavigationController+UIToolBar相关推荐

  1. 禁用UITabBarController双击事件

    http://blog.csdn.net/ipromiseu/article/details/7031084 很多时候我们的程序操作结构都是UITabBarController+UINavigatio ...

  2. iOS开启个人热点的纵向适配

    一.iPhone创建个人热点 iPhone/iOS双环上网,即iPhone通过创建个人热点(Personal Hotspot)实现共享上网,支持便携式Wi-Fi热点.蓝牙共享网络和USB共享网络. 1 ...

  3. iPhone/iOS开启个人热点的纵向适配小结

    http://blog.csdn.net/phunxm/article/details/42967035 一.iPhone创建个人热点 iPhone/iOS双环上网,即iPhone通过创建个人热点(P ...

  4. iPhone/iOS开启个人热点的相关位置调整小结

    冬至已到,圣诞将近,最近公司项目实在太多,三四个项目反复的切换真的让人焦头烂额,趁今天有点空,把维护的三个项目顺利送出,刚好可以缕缕思路,记录一下最近遇到的问题.说不着急那是假的,客户一天天的催的确实 ...

  5. ESTabBarController

    为什么要使用? 在开发工作中,我们可能会遇到需要自定义UITabBar的情况.例如:改变文字样式.添加一些动画效果.设置一个比默认更大的样式等等,以上需求如果只通过UITabBarItem往往很难实现 ...

  6. 【原】iOS学习之UITabBar的隐藏

    当页面使用 UITabBarController + UINavigationController 框架的时候,当跳转到详情页面的时候,如果 UITabBar 仍然存在的话就会造成逻辑混乱,用户体验也 ...

  7. iOS屏幕旋转技术点及解决方案总结

    1.屏幕旋转相关枚举 关于屏幕旋转枚举一共有3种: UIInterfaceOrientation,    UIInterfaceOrientationMask,   UIDeviceOrientati ...

  8. ios启动时间优化--理论

    启动时间是衡量应用品质的重要指标. 本文首先会从原理上出发,讲解iOS系统是如何启动APP的,然后从main函数之前和main函数之后俩个角度去分析如何优化启动时间. mach-O 哪些名词指的是Ma ...

  9. iOS App 百思不得姐

    项目介绍 仿照百思不得姐,通过看视频学习自己实践并简单总结项目开发过程中普遍遇到的问题,并且将可以用到其他项目中的分类方法进行简单总结,便于以后在别的项目中使用. 每天任务 1. 实现相应功能 2. ...

最新文章

  1. 产品经理的「七宗罪」
  2. C++实现array right rotation数组右旋转(附完整源码)
  3. python文件处理seek()方法的参数是_Python 文件(File) seek() 方法
  4. 那篇让汤普金斯进入梦境的相对论演讲
  5. 【转载】那么明亮的sz4j
  6. java override 用法_Java中@Override的作用
  7. pytorch输出分类结果并显示每个类别的概率
  8. snoopy php https_php使用snoopy与curl模拟登陆的实例分享
  9. LM393实现简易PWM调压电路
  10. 物联网数据多又杂?好用的数据可视化服务来了
  11. 动态规划算法二项式计算c语言,动态规划 — 计算二项式系数
  12. 点餐APP 冲刺三总结
  13. Android6.0通讯录权限问题
  14. 无法登录QQ和wegame,连接超时
  15. 基于Xposed框架截取安卓手机应用数据信息
  16. Git中smart Checkout与force checkout
  17. java ssm企业车辆汽车信息管理系统
  18. IRF系列场效应管参数表
  19. 01-4 哪些指令不能重排:Happen-Before规则
  20. 将本地电脑搭建的网页发布到公网

热门文章

  1. 用python画漂亮图片-Python 竟能绘制如此酷炫的三维图
  2. 在哪里学python比较好-学Python从哪里开始?
  3. python学习方向-学习Python的六大发展方向,你知道吗?
  4. python网课什么平台好-python网课什么平台好
  5. 软件测试用python一般用来做什么-python软件测试
  6. python官网下载步骤linux-CentOS 7.* 安装 python3.8.2 步骤
  7. python读取文件某一行-使用python读取.text文件特定行的数据方法
  8. 初学者python用哪个版本好-什么是Python?初学者应该学python哪个版本?
  9. 从零开始学python数据分析-从零开始学Python数据分析与挖掘 PDF 扫描版
  10. python读音发音器-python3-文本读音器