ios定制中间突出的tabBar
来源:互联网 发布:mysql insert语句 日期 编辑:程序博客网 时间:2024/04/28 15:24
先展示效果图:
这个tabBar纠结了我好久,最后通过查询资料各种百度谷歌终于找到一个比较符合我们需求的案例,下面展示出代码供各位参考
@interface BaseTabBarViewController ()<UITabBarControllerDelegate>@property (nonatomic,strong)UIButton *button;@end@implementation BaseTabBarViewController@synthesize button;#pragma mark- setup-(void)setup{ // 添加突出按钮 [self addCenterButtonWithImage:[UIImage imageNamed:@"我的钱"] selectedImage:[UIImage imageNamed:@"我的钱"]]; // UITabBarControllerDelegate 指定为自己 self.delegate=self; // 指定当前页——中间页 //self.selectedIndex=0; // 设点button状态 //button.selected=YES; // 设定其他item点击选中颜色 }#pragma mark - addCenterButton// Create a custom UIButton and add it to the center of our tab bar-(void) addCenterButtonWithImage:(UIImage*)buttonImage selectedImage:(UIImage*)selectedImage{ button = [UIButton buttonWithType:UIButtonTypeCustom]; [button addTarget:self action:@selector(pressChange:) forControlEvents:UIControlEventTouchUpInside]; button.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin; // 设定button大小为适应图片 button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height); [button setImage:buttonImage forState:UIControlStateNormal]; [button setImage:selectedImage forState:UIControlStateSelected]; // 这个比较恶心 去掉选中button时候的阴影 button.adjustsImageWhenHighlighted=NO; /* * 核心代码:设置button的center 和 tabBar的 center 做对齐操作, 同时做出相对的上浮 */ CGPoint center = self.tabBar.center; center.y = center.y - buttonImage.size.height/4; button.center = center; [self.view addSubview:button];}-(void)pressChange:(id)sender{ self.selectedIndex=1; button.selected=YES;}#pragma mark- TabBar Delegate// 换页和button的状态关联上- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{ if (self.selectedIndex==1) { button.selected=YES; }else { button.selected=NO; }}
- (void)viewDidLoad { [super viewDidLoad]; [self setTabBarVC]; [self setup]; [self addButtonNotifation]; self.tabBar.barTintColor = [UIColor whiteColor];}//添加大圆按钮的通知-(void)addButtonNotifation{ [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(buttonHidden) name:@"buttonNotifationCenter" object:nil]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(buttonNotHidden) name:@"buttonNotHidden" object:nil];}-(void)buttonNotHidden{ button.hidden=NO;}-(void)buttonHidden{ button.hidden=YES;}// 初始化所有子控制器- (void)setTabBarVC{ [self setTabBarChildController:[[SelectionViewController alloc] init] title:@"每月送" image:@"每月送" selectImage:@"每月送选中"]; [self setTabBarChildController:[[MyMoneyViewController alloc] init] title:@"我的钱" image:@"" selectImage:@""]; [self setTabBarChildController:[[MainViewController alloc] init] title:@"个人中心" image:@"个人中心" selectImage:@"个人中心选中"];}// 添加tabbar的子viewcontroller- (void)setTabBarChildController:(UIViewController*)controller title:(NSString*)title image:(NSString*)imageStr selectImage:(NSString*)selectImageStr{ UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:controller]; nav.tabBarItem.title = title; nav.tabBarItem.image = [[UIImage imageNamed:imageStr]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; nav.tabBarItem.selectedImage = [[UIImage imageNamed:selectImageStr]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; [nav.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10],NSForegroundColorAttributeName:RGBA(74, 74, 74, 1.0)} forState:UIControlStateNormal]; [nav.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10],NSForegroundColorAttributeName:RGBA(255, 200, 0, 1.0)} forState:UIControlStateSelected]; [self addChildViewController:nav];}
tabBar的颜色各位可以用一张白色的图片做背景
关于那个隐藏大圆按钮的通知,我发现导航推进下一页的时候那个大圆按钮不会消失,我就只好用了一个通知控制隐藏和显示如果各位有更好的方法也希望能够告知,共同进步
代码下载地址http://download.csdn.net/detail/shan1991fei/9557471
1 0
- ios定制中间突出的tabBar
- ios定制中间突出的tabBar
- iOS 中间按钮突出的tabbar
- IOS 定制中间突出UItabBar
- IOS 定制中间突出UItabBar
- iOS 自定制TabBar(中间是一个大按钮)
- 实现Tabbar的中间按钮向上突出的两种方法
- iOS tabbar中间添加按钮
- iOS tabbar中间添加按钮
- iOS 自定义 中间带突起圆形的tabbar
- iOS之UI TabBarcontroller----自定义tabBar/改变tabBar中间按钮的样式(一)
- 自定义TabBar中间的Item
- iOS Tabbar中间添加凸起按钮
- 底部按钮中间突出
- 猫猫学iOS 之微博项目实战(4)微博自定义tabBar中间的添加按钮
- android:clipChildren妙用:底部的radioGroup中间的button突出
- android:clipChildren妙用:底部的radioGroup中间的button突出
- Android --中间突出的底部导航栏布局简单实现
- 10个学习Android开发的网站推荐
- 43、JavaScript的运动----任意属性值的运动---透明度的改变
- Glide图片加载
- H5及H5页面是什么意思?如何制作H5页面?
- xUtils 源码解析
- ios定制中间突出的tabBar
- Python3字符串各种内置函数详解
- 乡村道路 problem d
- iOS开发经验--ios右滑返回时候与scrollview滑动冲突的问题
- jenkins视图插件extreme feedback
- EventBus 源码解析
- winform MouseWheel事件无效
- Fresco-FaceBook推出的Android图片加载库
- android studio 的gitignore