IOS 一个继承UINavigationController的子类

#import <UIKit/UIKit.h>

@interface BasicNavigationController : UINavigationController

@end

#import "BasicNavigationController.h"

@interface BasicNavigationController ()

@end

@implementation BasicNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 1.appearance方法返回一个导航栏的外观对象
    // 修改了这个外观对象,相当于修改了整个项目中的外观
    UINavigationBar *bar = [UINavigationBar appearance];
    // 2.设置导航栏的背景图片
    //2.1修改导航栏系统返回箭头图片
    bar.backIndicatorImage = [UIImage imageNamed:@"nav_backItem_white"];
    bar.backIndicatorTransitionMaskImage = [UIImage imageNamed:@"nav_backItem_white"];
    //2.2设置shadowImage
    [bar setBarStyle:UIBarStyleBlackTranslucent];
    bar.shadowImage = [[UIImage alloc] init];
    //2.3设置导航栏颜色
    [bar setTintColor:[UIColor whiteColor]];
    [bar setBarTintColor:KGlobalBlueColor];
    // 3.设置导航栏文字的主题
    [bar setTitleTextAttributes:@{
                                  NSFontAttributeName : KFontHeadline,
                                  NSForegroundColorAttributeName : [UIColor whiteColor]
                                  }];
    // 4.修改所有UIBarButtonItem的外观
    UIBarButtonItem *barItem = [UIBarButtonItem appearance];
    //4.1设置返回不需要文字
    //注:添加此方法,切换应用会出现一闪
//    [barItem setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];
    // 5.修改item上面的文字样式
    NSDictionary *dict = @{
                           NSFontAttributeName: KFontSubhead,
                           NSForegroundColorAttributeName : [UIColor whiteColor]
                           };
    NSDictionary *dictEnable = @{
                                 NSFontAttributeName: KFontSubhead,
                                 NSForegroundColorAttributeName: KGreyColor,
                                 };
    [barItem setTitleTextAttributes:dict forState:UIControlStateNormal];
    [barItem setTitleTextAttributes:dict forState:UIControlStateHighlighted];
    [barItem setTitleTextAttributes:dictEnable forState:UIControlStateDisabled];
}

@end



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值