由于最近做项目,需要使界面上的状态栏文字颜色变为白色,背景色变为自定义颜色。经过网上一番查找资料后,找到了比较方便的解决方案,废话不多说,直接上代码!
#define isIos7 ([[[UIDevice currentDevice] systemVersion] floatValue])
UIView *statusBarView = [[UIImageView alloc] initWithFrame:CGRectMake(0.f, 0.f, self.view.frame.size.width, 0.f)];
if (isIos7 >= 7 && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1)
{
statusBarView.frame = CGRectMake(statusBarView.frame.origin.x, statusBarView.frame.origin.y, statusBarView.frame.size.width, 20.f);
statusBarView.backgroundColor = [UIColor clearColor];
((UIImageView *)statusBarView).backgroundColor = [UIColor colorWithRed:106.0/255.0f green:187.0/255.0f blue:47.0/255.0f alpha:1];
[self.view addSubview:statusBarView];
}
上面的代码能够使状态栏的颜色实现自定义
而要实现文字变为白色
- (UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}