UI-自定义TabBar
MyCustomTabBar.h文件
#import <UIKit/UIKit.h>
@interface MyCustomTabBar : UITabBarController
@end
MyCustomTabBar.m文件
#import "MyCustomTabBar.h"
#define kDeviceHeigh [UIScreen mainScreen].bounds.size.height
@interface MyCustomTabBar ()<UITabBarDelegate>
@end
@implementation MyCustomTabBar
-(void)viewDidLoad{
[super viewDidLoad ];
//自定义TabBar
UITabBar *tabBar = [[UITabBar alloc]initWithFrame:self.tabBar.frame];
tabBar.userInteractionEnabled = YES;
[self.view addSubview:tabBar];
tabBar.backgroundImage = [UIImage imageNamed:@"tabbg"];
// 添加5个
for (int i = 1 ; i <= 5 ; i ++ ) {
// 获取按钮普通状态和选中状态的两个图片的名称
NSString *imgName = [NSString stringWithFormat:@"TabBar%d", i];
NSString *selImgName = [NSString stringWithFormat:@"TabBar%dSel", i];
// 创建按钮
UIButton *tabBtn = [[UIButton alloc]init ];
CGFloat width = self.view.bounds.size.width / 5;
// 设置按钮的frame
tabBtn.frame =CGRectMake((i-1) * width , 0 , width , 44);
if ( i == 3 ) {
tabBtn.frame = CGRectMake(tabBtn.frame.origin.x , tabBtn.frame.origin.y - 20, tabBtn.frame.size.width, 44 + 20 );
[tabBtn setBackgroundImage:[UIImage imageNamed:@"logoff_btn_n"] forState:UIControlStateNormal];
}else{
// 设置按钮普通状态和选中状态显示的图片
[tabBtn setBackgroundImage:[UIImage imageNamed:imgName] forState:UIControlStateNormal];
[tabBtn setBackgroundImage:[UIImage imageNamed:selImgName] forState:UIControlStateSelected ];
}
tabBtn.tag = 10 + i;
[tabBtn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
[tabBar addSubview:tabBtn];
}
}
-(void)btnClicked:(UIButton *)button{
for (int i = 1 ; i <= 5 ; i++ ) {
UIButton *btn = (UIButton *) [ self.view viewWithTag:10 + i];
if (btn != button) {
btn.selected = NO;
}
}
button.selected = YES;
if (button.tag == 13) {
UIViewController *vc = [[UIViewController alloc]init];
vc.view.backgroundColor = [UIColor orangeColor];
[self presentViewController:vc animated:YES completion:nil];
return;
}
self.selectedIndex = button.tag - 11;
}
@end
AppDelegate.m文件
#import "AppDelegate.h"
#import "MyCustomTabBar.h"
#import "FifthVC.h"
#import "SecondVc.h"
#import "ThirdVC.h"
#import "FourthVC.h"
#import "FirstVC.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//先创建五个控制器对象
FirstVC *firstVC = [[FirstVC alloc]init];
SecondVc *secondVC = [[SecondVc alloc] init];
ThirdVC *thirdVC = [[ThirdVC alloc]init];
FourthVC *fourthVC = [[FourthVC alloc]init];
FifthVC *fifthVC = [[FifthVC alloc]init];
// 创建TabBar控制器对象
MyCustomTabBar *tabBarVC = [[MyCustomTabBar alloc]init];
// 设置Tabbar的子控制器对象, 需要注意的是,TabBar控制器最多只能显示五个子视图,如果超过5个,它会只显示4个,把其他的放More选项中
tabBarVC.viewControllers = @[firstVC, secondVC, thirdVC, fourthVC, fifthVC];
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = tabBarVC;
[self.window makeKeyAndVisible];
return YES;
}
UI-自定义TabBar的更多相关文章
- iOS框架搭建(MVC,自定义TabBar)--微博搭建为例
项目搭建 1.新建一个微博的项目,去掉屏幕旋转 2.设置屏幕方向-->只有竖向 3.使用代码构建UI,不使用storyboard 4.配置图标AppIcon和LaunchImage 将微博资料的 ...
- flutter 自定义tabbar 给tabbar添加背景功能
flutter 自带的tabbar BottomNavigationBar有长按水波纹效果,不可以添加背景图片功能,如果有这方面的需求,就需要自定义tabbar了 自定义图片 我们使用BottomAp ...
- 自定义tabBar
★★★★自定义tabBar★★★★★★★ Demo下载地址:https://github.com/marlonxlj/tabBarCustom.git 前言: 有的时候需求要对tabBar进行自定义的 ...
- IOS第二天-新浪微博 - 添加搜索框,弹出下拉菜单 ,代理的使用 ,HWTabBar.h(自定义TabBar)
********HWDiscoverViewController.m(发现) - (void)viewDidLoad { [super viewDidLoad]; // 创建搜索框对象 HWSearc ...
- 原生HTML5 input type=file按钮UI自定义
原生<input type="file" name="file" />长得太丑 提升一下颜值 实现方案一.设置input[type=file]透明度 ...
- iOS 隐藏自定义tabbar
iOS 隐藏自定义tabbar -(void)viewWillAppear:(BOOL)animated { NSArray *array=self.tabBarController.view.su ...
- iOS开发之功能模块--关于自定义TabBar条
只上项目中用到的代码: 1.实现重写TabBar的TabBarItem,然后在中间额外加一个按钮. #import <UIKit/UIKit.h> @interface BikeTabBa ...
- iOS开发项目之四 [ 调整自定义tabbar的位置与加号按钮的位置]
自定义tabbar与按钮的添加 01 - 把系统的tabbar用我们自己的覆盖 LHQTabBar *lhqTabBar = [[LHQTabBar alloc]init]; [self setVal ...
- 关于自定义tabBar时修改系统自带tabBarItem属性造成的按钮顺序错乱的问题相关探究
关于自定义tabBar时修改系统自带tabBarItem属性造成的按钮顺序错乱的问题相关探究 测试代码:http://git.oschina.net/Xiyue/TabBarItem_TEST 简 ...
- 第二篇、Swift_自定义 tabbar 的 badgeValue显示样式
在实际的开发中,我们常常需要根据实际的需求,去改变bageValue的显示样式,默认是红色的背景,白色的字体颜色 使用方式: class BKTabBarController: UITabBarCon ...
随机推荐
- Windows 7 下 Node.js 连接 Oracle
原创作者: sailtseng 1. 安装 Oracle 11g express 详见: <Windows 7 x64 安装 Oracle 11g Express> 2. 安装 Micr ...
- Ngfor遍历map的方法
Ngfor可以遍历list和数组,但如果想遍历map,可以使用下面的方式 在TypeScript文件中: let list = Object.keys(MyObject); 在html文件中: *ng ...
- [笔记]Python的调试器pudb简易教程
Linux下运行python脚本,pudb是一个不错的调试器. 语法高亮,断点,调用栈,命令行,都有了,如下图. [安装] pip install pudb [使用] pudb xxx.py [快捷键 ...
- slf4j-api、slf4j-log4j12以及log4j之间什么关系?
几乎在每个jar包里都可以看到log4j的身影,在多个子工程构成项目中,slf4j相关的冲突时不时就跳出来让你不爽,那么slf4j-api.slf4j-log4j12还有log4j他们是什么关系?我把 ...
- linux命令(6/11)--修改文件的用户组chgrp和文件所有者chown
在lunix系统里,文件或目录的权限的掌控以拥有者及所诉群组来管理.可以使用chgrp指令取变更文件与目录所属群组,这种方式采用群组名称或群组识别码都可以.Chgrp命令就是change group的 ...
- ajax 事件使用
error: function (XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.status); alert(XMLH ...
- Django- 反向生成url
Django中提供了一个关于URL的映射的解决方案, 1.客户端的浏览器发起一个url请求,Django根据URL解析,把url中的参数捕获,调用相应的试图,获取相应的数据,然后返回给客户端显示 2. ...
- Qt debug和release
debug会默认给变量赋初始值,但是release不会. 所以: 在头文件中声明指针P* p时,最好给它初始化:P* p=NULL; 不然有可能造成野指针的情况
- js 的编译
js和其他语言一样,也是需要编译的,代码编译发生在代码执行之前,js代码的编译会经历如下几个阶段 1.分词,词法分析 这个过程会将由字符串组成的字符分解成有意义的代码块,这些代码块称为词法单元,例如 ...
- What's the difference between UTF-8 and UTF-8 without BOM?
https://stackoverflow.com/questions/2223882/whats-the-difference-between-utf-8-and-utf-8-without-bom ...