如何在iOS 7中更改导航栏颜色? [英] How to change Navigation Bar color in iOS 7?

查看:127
本文介绍了如何在iOS 7中更改导航栏颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在iOS 7中更改导航栏颜色?

How do I change the Navigation Bar color in iOS 7?

基本上我想要实现类似Twitter Nav Bar(更新Twitter的 iOS7 即是。我嵌入了视图控制器顶部的导航栏。我想要的是将导航栏颜色更改为浅蓝色以及顶部的实用工具栏。我似乎无法在我的故事板中找到一个选项

Basically I want to achieve something like the Twitter Nav Bar (updated Twitter for iOS7 that is). I embedded-in a nav bar atop a view controller. All I want is to change the nav bar color to light blue along with the utility bar at the top. I can't seem to find an option in my storyboard.

推荐答案

在iOS 7.0中,条形码的 tintColor 的行为已更改。它不再影响酒吧的背景。

The behavior of tintColor for bars has changed in iOS 7.0. It no longer affects the bar's background.

来自文档:

barTintColor Class Reference

应用于导航栏背景的色调颜色。

The tint color to apply to the navigation bar background.

@property(nonatomic, retain) UIColor *barTintColor

讨论 < br>
默认情况下,此颜色为半透明,除非您将半透明属性设置为

可用性

适用于iOS 7.0及更高版本。

Available in iOS 7.0 and later.

声明

UINavigationBar.h

NSArray *ver = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
if ([[ver objectAtIndex:0] intValue] >= 7) {
    // iOS 7.0 or later   
    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
    self.navigationController.navigationBar.translucent = NO;
}else {
    // iOS 6.1 or earlier
    self.navigationController.navigationBar.tintColor = [UIColor redColor];
}

我们也可以用它来检查iOS版本,如iOS 7用户界面转换指南

We can also use this to check iOS Version as mention in iOS 7 UI Transition Guide

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
        // iOS 6.1 or earlier
        self.navigationController.navigationBar.tintColor = [UIColor redColor];
    } else {
        // iOS 7.0 or later     
        self.navigationController.navigationBar.barTintColor = [UIColor redColor];
        self.navigationController.navigationBar.translucent = NO;
    }

编辑
使用xib

EDIT Using xib

这篇关于如何在iOS 7中更改导航栏颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆