UINavigationBar 的设置

来源:互联网 发布:everyonepiano软件下载 编辑:程序博客网 时间:2024/05/17 12:54
由于UINavigationBar的特殊性;(有两层,不能直接设置透明度和颜色)

//改变NavigationBar的颜色
1. self.navigationController.navigationBar.tintColor = [UIColor redColor];

2.给NavigationBar增加类别(Category),如下,之后可以使用如下一行代码修改透明度和颜色

self.navigationController.navigationBar.backgroundColor = [[UIColorlightGrayColorcolorWithAlphaComponent:0];



类别:
.h

#import <UIKit/UIKit.h>

@interface UINavigationBar (MyBar)

@end


.m

#import "UINavigationBar+MyBar.h"

@implementation UINavigationBar (MyBar)

- (instancetype)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        for (UIView * view in self.subviews)

        {

            if([view isKindOfClass:NSClassFromString(@"_UINavigationBarBackGround")])

            {

                [view removeFromSuperview];

            }

        }

    }

    return self;

}

@end




# 导航栏底下的黑线
[navigationBar  setBackgroundImage:[UIImage imageNamed:@"   "] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault]; 
[navigationBar setShadowImage:[UIImage new]];

#设置导航栏的背景色和文字颜色

1.

[[UINavigationBarappearance]setBackgroundImage:[UIImageimageWithPureColorBackgroundImage:[UIColorredColor].CGColorwithSize:CGSizeMake(1,64)]forBarMetrics:UIBarMetricsDefault];

2.

[[UINavigationBarappearance] setBackgroundImage:[UIImageimageNamed:@"systemNavigationBar.png"]forBarPosition:UIBarPositionAnybarMetrics:UIBarMetricsDefault];



#导航栏菜单文本颜色

[[UINavigationBarappearance]setTintColor:[UIColorwhiteColor]];//导航栏菜单文本颜色






0 0
原创粉丝点击