2015-02-25 13:48:04 u012661893 阅读数 588

iOS设置导航栏颜色以及状态栏字体颜色
下面是代码:

    [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
[SingleViewObject customNavigationBar:self.navigationController color:[UIColor redColor]];
self.navigationController.navigationBar.translucent = NO;
self.navigationController.navigationBar.barTintColor = [UIColor brownColor];


 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];//黑体白字
 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];//黑体黑字
 [application setStatusBarHidden:YES];//隐藏状态栏

其中translucent的值为NO,表示导航栏不是半透明的以及子视图的(0,0)位置在导航栏的下面,也就是整个window(0,64)的位置,
如果translucent设置为YES,导航栏为半透明,其余视图的(0,0)就是window的(0,0)位置

希望可以帮助到大家,如果有不对的地方希望大家多多指点。。。

2015-07-07 16:18:58 LiChang719 阅读数 3490

如果是storyboard 直接embed一个导航栏,然后在新出现的导航栏 选属性 选一下颜色就可以了

代码实现背景颜色修改:self.navigationController.navigationBar.barTintColor = [UIColor blueColor];




代码实现背景图片修改:当然在属性里面也是可以添加修改的[self.navigationController.navigationBar setBackgroundImage: [UIImage imageNamed:@"banner.png"] forBarMetrics:UIBarMetricsDefault];

2016-01-18 20:47:48 lolevergreen 阅读数 2292
1.方法一
UINavigationBar *navigationBar = self.navigationController.navigationBar;
// white.png图片自己下载个纯白色的色块,或者自己ps做一个
[navigationBar setBackgroundImage:[UIImage imageNamed:@"white.png"]
                   forBarPosition:UIBarPositionAny
                       barMetrics:UIBarMetricsDefault];
[navigationBar setShadowImage:[UIImage new]];

//容易造成不透明效果

2.方法二
1)声明UIImageView变量,存储底部横线
@implementation MyViewController {
    UIImageView *navBarHairlineImageView;
}
2)在viewDidLoad中加入:
navBarHairlineImageView = [self findHairlineImageViewUnder:navigationBar]

3)- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
            return (UIImageView *)view;
    }
    for (UIView *subview in view.subviews) {
        UIImageView *imageView = [self findHairlineImageViewUnder:subview];
        if (imageView) {
            return imageView;
        }
    }
    return nil;
}

最后在viewWillAppear,viewWillDisappear中处理
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    navBarHairlineImageView.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    navBarHairlineImageView.hidden = NO;
}

3.方法三
self.navigationController.navigationbar.barstyle = uiBaseline...None;
这个会留下细细的痕迹

4.方法四
    if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){

        NSArray *list=self.navigationController.navigationBar.subviews;

        for (id obj in list) {

            if ([obj isKindOfClass:[UIImageView class]]) {          
                UIImageView *imageView=(UIImageView *)obj;
                imageView.hidden=YES;   
            }           
        }
    }

ios导航栏、状态栏 颜色改变

博文 来自: shuaidan19920412

iOS导航栏颜色

阅读数 566

没有更多推荐了,返回首页