Moh*_*lah 1 cocoa-touch objective-c ios7
我有一些顶部有工具栏的视图控制器,看起来像这样
我如何填充状态栏背景以匹配工具栏背景,以便它匹配新的iOS 7风格?
您需要在app delegate中添加子视图并根据自己的喜好更改颜色.这是一个代码示例applicationdidfinishLaunchingWithOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Override point for customization after application launch.
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 320, 20);
//change this to match your navigation bar or view color or tool bar
//You can also use addStatusBar.backgroundColor = [UIColor BlueColor]; or any other color
addStatusBar.backgroundColor = [UIColor colorWithRed:0.973/255. green:0.973/255. blue:0.973/255. alpha:1];
[self.window.rootViewController.view addSubview:addStatusBar];
}
return YES;
}
Run Code Online (Sandbox Code Playgroud)
看一下评论.您可以使用任何类型的颜色addStatusBar.backGroundColor来匹配您需要的颜色.请注意,此处带红色的颜色只是产生黑色背景,将其更改为您需要的任何颜色.对于深灰色,用以下代码替换它:
addStatusBar.backgroundColor = [UIColor colorWithRed:85.0/255.0 green:85.0/255.0 blue:85.0/255.0 alpha:1];
Run Code Online (Sandbox Code Playgroud)
编辑:
要更改单个视图中的状态栏颜色,您只需在方法中插入以下代码(将访问您要更改的视图),ViewDidLoad之后[super viewDidLoad];应该在您放置代码的视图中更改状态栏的颜色.
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 320, 20);
addStatusBar.backgroundColor = [UIColor colorWithRed:0.973/255. green:0.973/255. blue:0.973/255. alpha:1];
[self.view addSubview:addStatusBar];
Run Code Online (Sandbox Code Playgroud)
EDIT1:
如果尝试在导航控制器的唠叨栏顶部添加子视图,则必须将子视图的位置增加两倍,如下所示:
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, -20, 320, 20);
addStatusBar.backgroundColor = [UIColor colorWithRed:127.0/255. green:0.0/255. blue:127.0/255. alpha:1];
[self.view addSubview:addStatusBar];
[self.navigationController.navigationBar addSubview:addStatusBar];
Run Code Online (Sandbox Code Playgroud)
此外,您还需要将子视图添加为导航控制器导航栏的子视图.我将子视图的背景颜色设置为紫色,但您可以更改它.
| 归档时间: |
|
| 查看次数: |
6157 次 |
| 最近记录: |