仅更改UITableView的主体颜色或仅更改状态栏颜色 [英] Changing only the body colour of UITableView or changing only the status bar colour

查看:90
本文介绍了仅更改UITableView的主体颜色或仅更改状态栏颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为iOS状态栏获取特定的颜色,我知道它将采用顶视图控制器视图的颜色. 因此,我可以通过将状态栏所需的颜色应用于表格视图来获得此效果,该外观如下所示

I wanted to get a specific colour to the iOS status bar ,I understand it will take the colour of the top view controllers view . And hence I can get this by applying the colour I want for the status bar to the table view ,which would look like this

但是当它没有任何行时,整个表格视图就会得到该颜色(很明显!但这不是我想要的)

But when it doesn't have any rows then whole table view gets that color (Obvious! but thats not what i want)

是否有任何方法可以仅将颜色赋予表格视图的顶部,以便状态栏获得该颜色,或者我可以单独更改状态栏的颜色. 我有

Is there any way to give colour only to the top part of the tableview so that status bar gets that colour or can i change the status bar color alone . I have

基于控制器的状态栏外观

View controller-based status bar appearance

在Info.plist中为NO.

in Info.plist as NO .

推荐答案

您可以将背景颜色应用于状态栏,如下所示

You can apply background color to status bar like following

UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];

if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
    statusBar.backgroundColor = [UIColor redColor];
}

在AppDelegate didFinishLaunchingWithOptions方法中使用上面的代码将更改整个应用程序的状态栏背景颜色.如果要将背景色更改为特定的视图控制器,则应遵循@Lion's方法.

Using the above code in AppDelegate didFinishLaunchingWithOptions method would change the status bar background color of entire app. If you want to change the background color to specific view controllers, then you should follow the @Lion's approach.

希望这会有所帮助.

这篇关于仅更改UITableView的主体颜色或仅更改状态栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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