自定义Status Bar的基本方法
2012-03-07 20:31 张智清 阅读(1070) 评论(0) 编辑 收藏 举报方法一:利用私有API添加新图标
直接上代码:在具体视图控制器中重写addStatusBarImageNamed:removeOnExit:方法
- (void) addStatusBarImageNamed:(NSString*)image removeOnExit: (BOOL) remove {
if(_statusbarimage!=nil && _responds) {
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"statusBarEnabled"] integerValue] == 1)
[self removeStatusBarImageNamed:_statusbarimage];
statusbarimage=image;
}
if (_responds) {
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"statusBarEnabled"] integerValue] == 1)
[super addStatusBarImageNamed:image removeOnExit: remove];
}
}
方法二:用新的UIWindow覆盖原来的状态栏
装载自:http://b.imi.im/?p=374
首先继承UIWindow,及init的方法,关键语句self.windowLevel = UIWindowLevelAlert;
- (id)init
{
CGRect f = [[UIScreen mainScreen] bounds]; //获取屏幕区
CGRect s = [[UIApplication sharedApplication] statusBarFrame]; //获取状态栏框架区
self = [super initWithFrame:CGRectMake(0,0,f.size.width, s.size.height)];
if(self != nil) {
self.windowLevel = UIWindowLevelAlert;
self.backgroundColor = [UIColor clearColor];
[self makeKeyAndVisible];
}
return self;
}