iphone 自定义Status Bar

方法一:利用私有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; }
复制代码

你可能感兴趣的:(status,自定义,Bar)