导航栏随手记

一 状态栏(UIStatusBar)

状态栏 即是整个页面最上面 像素高20的位置

分两部分 前景部分:信号 电池 时间等字体 有两种状态  默认的黑色(UIStatusBarStyleDefault

                                                                 白色(UIStatusBarStyleLightContent)  

           背景部分:后面的颜色 背景图片

对于前景部分的改变:整体转变  

          

1.plist设置statusBar

在plist里增加一行 UIStatusBarStyle(或者是“Status bar style”也可以),这里可以设置两个值,就是上面提到那两个 
UIStatusBarStyleDefault 和 UIStatusBarStyleLightContent

这样在app启动的launch页显示的时候,statusBar的样式就是上面plist设置的风格。

2.代码改变

  在plist里增加一行 View controller-based status bar appearance  设置NO;

 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContentanimated:NO]]

;


对于背景部分改变


1.要是需要存在导航功能的
[self.navigationController.navigationBar setBarTintColor:[UIColor redColor]];
是状态栏和导航栏整体颜色一致且改变

或者 UIImageView *statusBarView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -20, self.view.frame.size.width, 20)];
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];
导航栏和状态栏颜色可以不一致


2.要是不需要导航功能的
self.navigationController.navigationBar.hidden=YES;
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
view.backgroundColor=[UIColor greenColor];
直接导航栏隐藏  在view或者UIIMagView上面增加相应的功能就行



二.导航栏

 导航栏像素点 44 
导航栏实际上是UINavigationController独有的功能,对于上面一般的 例如返回键 item  
可以直接操作  self.navigationItem.leftBarButtonItem.title=@"返回";
有一些属性   ,可以点进去看看。 
或者一般
UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
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;
  用这种自定义的 
   当然 你想要 例如返回键位置改变一下 写某些位置信息  要偏下  上面两种方法就不行啦
还是两种方法可以实现    1.还是定义button 但是可以 [self.navigationController.navigationBar addSubview:btn];

这种效果是 还是保 持导航的那种默认效果的跳转页面 左右跳转 但是往下延伸的二级页面 在导航栏位置上面也存在btn;
                                        2.直接隐藏导航栏  用View代替 随便你做任何处理   但就是跳转页面的效果就的自己处理啦。

三.UITabBarController

现在大部分的界面上面有需要类似的功能 一般的系统自带的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;
}


可能说的不全面 我这也是仅仅对初入者可能会有帮助 要是错误的话 敬请指教






 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值