0
点赞
收藏
分享

微信扫一扫

iOS开发之--最简单的导航按钮更换方法/导航颜色的改变

有很多时候,我们需要用到导航,那么更换导航的时候,是在那用那修改,还是自定义一个导航,或者是声明一个代理方法,经过查资料和对导航属性的一些了解,用一种方法最为简单,就是在入口类里面添加一个方法,调用偏移量的方法,达到隐藏默认导航按钮的效果,代码如下:

- (void)setNaviBack{
    UIFont *font = [UIFont systemFontOfSize:16.f];
    //title的颜色和字体大小
    NSDictionary *textAttributes = @{
                                     
                                     NSFontAttributeName : font,
                                     
                                     NSForegroundColorAttributeName : [UIColor whiteColor]
                                     
                                     };
    
    
    UINavigationBar * navigationBar = [UINavigationBar appearance];
    navigationBar.titleTextAttributes = textAttributes;

//导航栏的背景颜色
    navigationBar.barTintColor = MainColor;
    
    //返回按钮的箭头颜色
    
    [navigationBar setTintColor:[UIColor colorWithRed:0.984 green:0.000 blue:0.235 alpha:1.000]];
    
    //设置返回样式图片
    
    UIImage *image = [UIImage imageNamed:@"返回"];
    
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    navigationBar.backIndicatorImage = image;
    
    navigationBar.backIndicatorTransitionMaskImage = image;
    
    UIBarButtonItem *buttonItem = [UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil];
    
    //设置图片与文本的偏移量
    UIOffset offset;
    
    offset.horizontal = - 500;
    
    offset.vertical =  - 500;
    
    [buttonItem setBackButtonTitlePositionAdjustment:offset forBarMetrics:UIBarMetricsDefault];
    
}

这样就可以了,每个页面的返回按钮都会被替换掉,效果如下:

iOS开发之--最简单的导航按钮更换方法/导航颜色的改变_偏移量

 


举报

相关推荐

iOS 调整导航栏按钮与边框的距离

简单的导航栏

0 条评论