iOS NavgationBar、NavigationItem专题、隐藏以及修改状态栏

 1.设置navigationItem.leftBarButtonItem 会覆盖掉系统自带的返回图标+返回title

    UIImage *image=[UIImage imageNamed:@"btn_arrow_left_normal"];

    UIButton *backButton=[UIButton buttonWithType:UIButtonTypeCustom];

    backButton.frame=CGRectMake(0, 0, image.size.width, image.size.height);

    [backButton setBackgroundImage:image forState:UIControlStateNormal];

    [backButton addTarget:self action:@selector(doBack) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];

    self.navigationItem.leftBarButtonItem = backItem;

2.设置导航栏标题 title 属性

 [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:

         RGBCOLOR(0xff, 0xff, 0xff), UITextAttributeTextColor, 

         [UIColor colorWithRed:0 green:0.7 blue:0.8 alpha:1], UITextAttributeTextShadowColor,

         [NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset,

         [UIFont systemFontOfSize:20.0], UITextAttributeFont, nil]];

3.自定义导航栏右边按钮

    UIButton rightSearch = [UIButton buttonWithType:UIButtonTypeCustom];

    [rightSearch setBackgroundImage:[UIImage imageNamed:@"right_search"] forState:UIControlStateNormal];

    [rightSearch addTarget:self action:@selector(doSearchTask:) forControlEvents:UIControlEventTouchUpInside];

    rightSearch.frame = CGRectMake(0, 0, 20, 20);

    UIBarButtonItem *settingNavBar = [[UIBarButtonItem alloc] initWithCustomView:rightSearch];

    self.navigationItem.rightBarButtonItem = settingNavBar;

4. 定制颜色

            [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; 
            [[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];//iOS7 later 修改导航栏背景颜色


            [[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@"btn_arrow_left_normal"]];
            [[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"btn_arrow_left_normal"]]; //这两个属性必须同时修改才能修改返回按钮的图标,都是iOS7Later

if (IOS7_OR_LATER) { //直接修改导航栏背景图片,注意iOS6和iOS7导航栏的区别
       [[UINavigationBar appearance] setBackgroundImage:[DXImageUtil imageWithColor:RGBCOLOR(0xff, 0x67, 0x00) andBounds:CGRectMake(0, 0, 320, 64)] forBarMetrics:UIBarMetricsDefault];
    } else {
        [[UINavigationBar appearance] setBackgroundImage:[DXImageUtil imageWithColor:RGBCOLOR(0xff, 0x67, 0x00) andBounds:CGRectMake(0, 0, 320, 44)] forBarMetrics:UIBarMetricsDefault];
    }

5. 修改状态栏属性或者方法

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];

    设置此属性时,请注意文档说法:// Setting statusBarHidden does nothing if your application is using the default UIViewController-based status bar system.如果想要正确使用这两个方法,我们需要在app-Info.plist中添加:

key   : View controller-based status bar appearance   value为:NO。否则不起任何作用


 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值