iOS设置NavigationBar颜色和BackButtonItem颜色

释放双眼,带上耳机,听听看~!

iOS设置NavigationBar颜色和BackButtonItem颜色,归档存储以备查阅,把以下代码添加到appdelegate的

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

//1. 设置导航栏的背景图片
UINavigationBar *bar=[UINavigationBar appearance];
//[bar setBackgroundImage:[UIImage imageNamed:@"navigationbar_background.png"] forBarMetrics:UIBarMetricsDefault];
[bar setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"navigationbar_background.png"]]];
bar.barStyle = UIStatusBarStyleDefault;
//1.2 设置返回按钮的颜色  在plist中添加 View controller-based status bar appearance=NO切记。
[bar setTintColor:kBackButtonColor];
//  //设置返回按钮指示器图片
//  UIImage *backImage=[[UIImage imageNamed:@"navigationbar_back"] resizableImageWithCapInsets:UIEdgeInsetsMake(5, 0, 5, 5)];
//  [[UINavigationBar appearance] setBackIndicatorImage:backImage];
//  [[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"navigationbar_back_highlighted"]];
//  
//2. 设置导航栏文字的主题
[bar setTitleTextAttributes:@{
NSForegroundColorAttributeName:[UIColor blackColor],
}];
//3. 设置UIBarButtonItem的外观
UIBarButtonItem *barItem=[UIBarButtonItem appearance];
[barItem setBackgroundImage:[UIImage imageNamed:@"navigationbar_button_background.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[barItem setBackgroundImage:[UIImage imageNamed:@"navigationbar_button_background_pushed.png"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
//4. 该item上边的文字样式
NSDictionary *fontDic=@{
NSForegroundColorAttributeName:kBackButtonColor,
NSFontAttributeName:[UIFont systemFontOfSize:19.f],  //粗体
};
[barItem setTitleTextAttributes:fontDic
forState:UIControlStateNormal];
[barItem setTitleTextAttributes:fontDic
forState:UIControlStateHighlighted];
// 5.设置状态栏样式
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

 

人已赞赏
iOS文章

iOS TableView与NavigationBar中间多出空白间隔

2020-5-12 21:42:08

iOS文章

iOS MBProgressHUD、SVProgressHUD基本使用方法

2020-5-12 22:31:55

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索