导航栏随手记
来源:互联网 发布:网络预约挂号平台 编辑:程序博客网 时间:2024/05/22 16:53
一 状态栏(UIStatusBar)
状态栏 即是整个页面最上面 像素高20的位置
分两部分 前景部分:信号 电池 时间等字体 有两种状态 默认的黑色(UIStatusBarStyleDefault)
白色(UIStatusBarStyleLightContent)
背景部分:后面的颜色 背景图片
对于前景部分的改变:整体转变
1.plist设置statusBar
在plist里增加一行 UIStatusBarStyle(或者是“Status bar style”也可以),这里可以设置两个值,就是上面提到那两个
UIStatusBarStyleDefault 和 UIStatusBarStyleLightContent
这样在app启动的launch页显示的时候,statusBar的样式就是上面plist设置的风格。
2.代码改变
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContentanimated:NO]]
;
statusBarView.image=[UIImage imageNamed:@"zhuangtailan.png"];
[self.navigationController.navigationBar addSubview:statusBarView];
UIImageView *statusBarView11 = [[UIImageView alloc] initWithFrame:CGRectMake(0,5, self.view.frame.size.width, 44)];
statusBarView11.image=[UIImage imageNamed:@"navgationbar.png"];
[self.navigationController.navigationBar addSubview:statusBarView11];
导航栏和状态栏颜色可以不一致
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
view.backgroundColor=[UIColor greenColor];
二.导航栏
backBtn.frame = CGRectMake(20, 10, 28, 28);
[backBtn setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
[backBtn addTarget:self action:@selector(doBack:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
self.navigationItem.leftBarButtonItem = backItem;
用这种自定义的
三.UITabBarController
在appdelegate里面 直接调用UITabBarController的viewControllers的属性即可
他的tabBar属性可以直接调用,进行图片设置 取得下面的items可以
UITabBar *tabBar = tabBarViewController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
也可以直接 viewController.item 直接取并进行图片和title的设置
假如直接ViewController.title进行设置 设置的是tabbar和navgationbar 的title
要想区分 可以在单独页面中对navgationbar的title 单独设置
viewController.navgationItem.title=@"";
这样的话 就对图片有严格的需求 24*24
我建议还是自定义吧 这样还是看上去代码更简单
关键点 是 tabBarViewController.tabBar隐藏 自定义tabbar 可以继承UIView
里面写方法 主要元素 直接展示的image 数组 点击的image数组 上面显示的title 以及对上面充当item 的button
的点击方法 主要的一点就是要关联相应的ViewController
代码:
myTaber.h
#import <UIKit/UIKit.h>@interface MyTabBar : UIView- (void)createTabBarWithBackgroundImageName:(NSString *)bgImageName andButtonsImageName:(NSArray *)buttonsImageName andButtonsSelectImageName:(NSArray *)buttonsSelectImageName andButtonsTitle:(NSArray *)buttonsTitle andSEL:(SEL)sel andClass:(id)classObject;@end
myTaber.m
#import "MyTabBar.h"@implementation MyTabBar- (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { // Initialization code } return self;}- (void)createTabBarWithBackgroundImageName:(NSString *)bgImageName andButtonsImageName:(NSArray *)buttonsImageName andButtonsSelectImageName:(NSArray *)buttonsSelectImageName andButtonsTitle:(NSArray *)buttonsTitle andSEL:(SEL)sel andClass:(id)classObject{ // 创建背景 [self createBackGroundImageWithImageName:bgImageName]; // 创建item for(int i=0;i<buttonsImageName.count;i++) { [self createItemWithButtonImageName:[buttonsImageName objectAtIndex:i] andButtonSelectImageName:[buttonsSelectImageName objectAtIndex:i] andTitle:[buttonsTitle objectAtIndex:i] andSEL:sel andClass:classObject andIndex:i]; }}- (void)createBackGroundImageWithImageName:(NSString *)imageName{ UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]]; imageView.frame = self.bounds; [self addSubview:imageView];}- (void)createItemWithButtonImageName:(NSString *)buttonImageName andButtonSelectImageName:(NSString *)buttonSelectImageName andTitle:(NSString *)title andSEL:(SEL)sel andClass:(id)classObject andIndex:(int)index{ UIView *groundView = [[UIView alloc] init]; groundView.frame = CGRectMake(0+self.bounds.size.width/4*index, 0, self.bounds.size.width/4, self.bounds.size.height); UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake((64-45)/2, 3, 65, 40); [btn setImage:[UIImage imageNamed:buttonImageName] forState:UIControlStateNormal]; [btn setImage:[UIImage imageNamed:buttonSelectImageName] forState:UIControlStateSelected]; [btn addTarget:classObject action:sel forControlEvents:UIControlEventTouchUpInside]; btn.tag = index; [groundView addSubview:btn]; UILabel *label = [[UILabel alloc] init]; label.frame = CGRectMake((64-45)/2, 35, 65, 8); label.text = title; label.textColor = [UIColor colorWithRed:0.30f green:0.30f blue:0.30f alpha:1.00f]; label.font = [UIFont systemFontOfSize:8]; label.textAlignment = NSTextAlignmentCenter; label.backgroundColor = [UIColor clearColor]; [groundView addSubview:label]; [self addSubview:groundView];}/*// Only override drawRect: if you perform custom drawing.// An empty implementation adversely affects performance during animation.- (void)drawRect:(CGRect)rect{ // Drawing code}*/@end
appledate.m中引用
tabBarVC.tabBar.hidden=YES; MyTabBar*_mytaB=[[MyTabBar alloc]init]; _mytaB.frame=CGRectMake(0, self.window.frame.size.height-49, self.window.frame.size.width, 49); [tabBarVC.view addSubview:_mytaB]; NSArray *buttonsImage = [[NSArray alloc] initWithObjects: @"1.jpg", @"2.jpg", @"3.jpg", @"4.jpg", nil]; NSArray *buttonsSelectImage = [[NSArray alloc] initWithObjects: @"tab_0_pre.png", @"tab_1_pre.png", @"tab_2_pre.png", @"tab_3_pre.png",nil]; NSArray *buttonsTitle =[[NSArray alloc]initWithObjects:@"12",@"34",@"",@"wi", nil]; [_mytaB createTabBarWithBackgroundImageName:@"tabbar.png" andButtonsImageName:buttonsImage andButtonsSelectImageName:buttonsSelectImage andButtonsTitle:buttonsTitle andSEL:@selector(btnClick:) andClass:self];
- (void)btnClick:(UIButton *)btn{ NSLog(@"%@ ,%@ ",[btn.superview class],[btn.superview.superview class]); 直接进去第一个页面是点击状态 UIView *tabbarView = btn.superview.superview; for(UIView *view in tabbarView.subviews) { if(![view isKindOfClass:[UIImageView class]]) { NSArray *subViews = view.subviews; UIButton *btn = (UIButton *)[subViews objectAtIndex:0]; btn.selected = NO; } } btn.selected = !btn.selected; tabBar.selectedIndex = btn.tag;}
- 导航栏随手记
- ios开发随手笔记-右侧导航栏
- .net随手记----导航条随下拉框一直置顶
- 随手记
- 随手记
- 随手记
- 随手记
- 随手记
- 随手记
- 随手记
- 随手记
- 随手记
- 随手记
- 随手记
- 随手记
- 随手记
- 随手记
- 随手记
- 基于 skynet 的 MMO 服务器设计
- Catch That Cow
- HDOJ题目4939 Stupid Tower Defense(dp)
- 树莓派的杂七杂八
- Fragment的生命周期以及使用技巧
- 导航栏随手记
- NDK环境搭建
- 第十三周阅读项目(4):多态性与虚函数
- SSH配置中问题 Unable to instantiate Action
- 添加pch文件
- /etc/hosts文件中的::1是什么意思
- 队残冒逃茸霞桥镭砸的
- 20150527
- 出现/usr/bin/ld:cannot find -lxxx的问题分析