美文网首页
OC/Swift 设置导航栏、状态栏字体与背景的颜色

OC/Swift 设置导航栏、状态栏字体与背景的颜色

作者: emily_sky | 来源:发表于2016-09-07 16:03 被阅读363次

一、导航栏属性设置

//  swift
//返回键去掉名字
self.navigationItem.backBarButtonItem = UIBarButtonItem.init(title: "", style: .plain, target: self, action: nil)
// 设置导航栏item指示色
self.navigationController?.navigationBar.tintColor = UIColor.white
/ /设置导航栏背景颜色
self.navigationController?.navigationBar.barTintColor = UIColor(red:0.23, green:0.60, blue:0.93, alpha:1.00)
//  设置导航栏标题颜色
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]


// OC
// 设置导航栏item指示色
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
 //  设置导航栏标题颜色与大小
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:17]};
//设置导航栏背景颜色
self.navigationController.navigationBar.barTintColor = CustomBlueColor;

// 在Appdelegate上设置导航控栏背景颜色
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:155/255.0 green:131/255.0 blue:255/255.0 alpha:1]];
// 在Appdelegate上标签栏的背景颜色
[[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:155/255.0 green:131/255.0 blue:255/255.0 alpha:1]];  
// 设置导航栏上文字的颜色
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
// tabbarbutton默认字体颜色
[[UITabBarItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor grayColor]} forState:UIControlStateNormal];
// tabbarbutton选中字体颜色
[[UITabBarItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor orangeColor]} forState:UIControlStateSelected];

二、设置状态栏文字颜色
第一步:在Info.plist中设置UIViewControllerBasedStatusBarAppearanceNO
第二步:在viewDidLoad中加一句

 // swift
UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent
 // OC
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

这样就可以把默认的黑色改为白色。

设置状态栏背景颜色

// 定义以下方法:
// swift
func setStatusBarBackgroundColor(color : UIColor) {
    let statusBarWindow : UIView = UIApplication.shared.value(forKey: "statusBarWindow") as! UIView
    let statusBar : UIView = statusBarWindow.value(forKey: "statusBar") as! UIView
    if statusBar.responds(to:#selector(setter: UIView.backgroundColor)) {
        statusBar.backgroundColor = color
   }
}
// 调用
self.setStatusBarBackgroundColor(color: UIColor(red:0.23, green:0.60, blue:0.93, alpha:1.00))


//  OC
- (void)setStatusBarBackgroundColor:(UIColor *)color {
    UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
    if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
    statusBar.backgroundColor = color;
    }
}

// 调用
[self setStatusBarBackgroundColor:CustomBlueColor];

相关文章

  • 设置导航栏颜色, 字体大小

    取出导航栏 设置导航栏背景色 设置标题颜色和字体大小 设置布局从导航栏下开始, 把导航栏设置为不透明 设置状态栏的...

  • iOS状态栏使用总结<转>

    目录: 一、状态栏与导航栏二、设置状态栏显隐与字体样式三、设置状态栏背景色四、启动页隐藏状态栏五、状态栏、导航栏相...

  • iOS状态栏使用总结

    目录: 一、状态栏与导航栏二、设置状态栏显隐与字体样式三、设置状态栏背景色四、启动页隐藏状态栏五、状态栏、导航栏相...

  • 导航栏UINavigationController

    2,设置导航栏的背景颜色 3,设置导航栏按钮字体颜色 4,设置标题样式与颜色(通过导航栏字典的方式) 5,设置返回...

  • 如何设置状态栏字体颜色

    改变状态栏样式,只对iOS7及以上系统有效。其实也就是改变状态栏的字体颜色,默认是黑色,可以根据导航栏背景颜色设置...

  • OC/Swift 设置导航栏、状态栏字体与背景的颜色

    一、导航栏属性设置 二、设置状态栏文字颜色第一步:在Info.plist中设置UIViewControllerBa...

  • iOS UINavigationController导航栏 设置

    只有电池栏颜色变化 而且 没有导航栏那条横线 导航栏字体大小和颜色 设置状态栏和导航栏是一致的颜色 设置透明的导航栏

  • UINavigationBar Tips

    设置所有导航栏的属性: 更改导航栏的背景颜色: 更改导航栏的文字颜色: 更改导航栏的标题字体及颜色: iOS字体查...

  • 导航条及状态栏的设置

    // 修改导航条背景色 // 修改导航条上字体颜色及大小 // 修改状态栏字体颜色

  • iOS 小功能实现总结

    一、导航栏1、状态栏(1)、更改状态栏的字体颜色参考博客:IOS上 关于状态栏的相关设置(UIStatusBar)...

网友评论

      本文标题:OC/Swift 设置导航栏、状态栏字体与背景的颜色

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