iOS导航栏

1.自定义导航栏返回按钮

fanhui@2x.png

1.首先得到一个UIImage对象

    UIImage *backButtonImage = [[UIImage imageNamed:@"fanhui.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 30, 0, 0)];

2.全局替换或者仅一个导航栏替换

//全局替换
    [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
//单个导航栏设置
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];

3.让按钮文字不在屏幕中显示

 [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];

2.设置系统导航栏的颜色

 UINavigationBar *appearance = [UINavigationBar appearance];
    // 设置导航条背景颜色,在iOS7才这么用
    [appearance setBarTintColor:[UIColor blueColor]];
    //        [appearance setBackgroundColor:[BaseColor colorWithNav]];
    // 设置导航条的返回按钮或者系统按钮的文字颜色,在iOS7才这么用
    [appearance setTintColor:[UIColor whiteColor]];
    // 设置导航条的title文字颜色,在iOS7才这么用
    [appearance setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                        [UIColor whiteColor], NSForegroundColorAttributeName, [UIFont systemFontOfSize:17], NSFontAttributeName, nil]];

3.隐藏显示状态栏和更改颜色

plist中


B1F0F438-6160-42C7-BF11-303A0F8C2379.png
//显示状态栏
    [[UIApplication sharedApplication]setStatusBarHidden:NO];
    //将状态栏颜色设为白色
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

4.导航栏透明

使用透明图片将导航栏变为透明


nav_bargound.png
#pragma mark - 视图将要出现
- (void)viewWillAppear:(BOOL)animated
{
    //导航栏背景
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_bargound.png"] forBarMetrics:UIBarMetricsDefault];
    
    //导航栏底部线
    self.navigationController.navigationBar.shadowImage =[UIImage imageNamed:@"nav_bargound.png"];
}
#pragma mark - 视图将要消失
- (void)viewWillDisappear:(BOOL)animated
{
    //导航栏背景
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    
    //导航栏底部线
    self.navigationController.navigationBar.shadowImage =[UIImage imageNamed:@""];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容