如何在按钮点按钮上将状态栏颜色更改为自定义颜色? 像热点被激活时的东西。
我想我可以在当前窗口中添加子视图并将背景属性设置为所需的颜色,但这是一个黑客,我想知道是否有更好的方法。
答案 0 :(得分:1)
试试这段代码:
在您的info.plist
中Set View controller-based status bar appearance to NO
Set Status bar style to UIStatusBarStyleLightContent
在AppDelegate
方法中:
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) // for ios7
{
UIView *yourview=[[UIView alloc] initWithFrame:CGRectMake(0, 0,320, 20)];
yourview.backgroundColor=[UIColor redColor];
[self.window.rootViewController.view addSubview:yourview];
}
我认为这会对你有所帮助。 :)
答案 1 :(得分:0)
使用此代码。
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,320, 20)];
view.backgroundColor=[UIColor redColor];
[self.window.rootViewController.view addSubview:view];
希望此代码对您有用。