美文网首页
导航栏的一些设置

导航栏的一些设置

作者: 张俊凯 | 来源:发表于2018-03-20 15:59 被阅读34次
  • 全局一次性设置导航栏的字体和颜色

集成UINavigationController,在viewDidLoad里面设置颜色和字体,用单例的方法

[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:THEME_COLOR}];
[[UINavigationBar appearance] setTintColor:THEME_COLOR];
  • 设置导航栏返回按钮为中文

显示当前导航栏的返回按钮为中文,必须在推出当前控制器的上一个控制器里设置才能显示效果,A push B,B控制器显示中文返回按钮,需要在A控制器进行设置

//A控制器 init方法里面
[self.navigationItem setBackBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"返回" style:0 target:nil action:nil]];

补充:在做一些基础设置的时候,可以把设置的方法放在控制器的 init方法里

-(instancetype)init{
    if (self = [super init]) {
        
        //做初始化的一些操作
        
    }
    return self;
    
}
  • 设置导航栏的阴影
    原理:在navigationBar的layer上进行操作,和普通的view实现阴影一个道理,下面是代码
    //1.设置阴影颜色

    self.navigationBar.layer.shadowColor = [UIColor blackColor].CGColor;

    //2.设置阴影偏移范围

    self.navigationBar.layer.shadowOffset = CGSizeMake(0, 1);

    //3.设置阴影颜色的透明度

    self.navigationBar.layer.shadowOpacity = 0.2;

    //4.设置阴影半径

    self.navigationBar.layer.shadowRadius = 2;

    //5.设置阴影路径
    self.navigationBar.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.navigationBar.bounds].CGPath;

相关文章

网友评论

      本文标题:导航栏的一些设置

      本文链接:https://www.haomeiwen.com/subject/ytsbqftx.html