我需要从 iPad 应用程序的状态栏中移除电池和手表图标。我怎样才能做到这一点?
user1344851
问问题
658 次
3 回答
2
不,你不能这样做。您只能删除完整的状态栏。
我不知道为什么人们会想要移除时钟和电池,但无论如何都要离开酒吧。
于 2012-10-04T21:43:49.217 回答
1
您可以使用UIWindow
布局为不透明视图的子类,复制状态栏的外观。您可以相应地设置它的框架,以便它只阻挡您需要隐藏的状态栏部分。然后将windowLevel
属性设置为类似UIWindowLevelStatusBar + 1.0f
. 希望这可以帮助!
编辑
我想出了一些基本的示例代码。这仅应被视为概念证明。值得生产代码的尝试有很多考虑因素,例如旋转、不同的状态栏样式(我想说半透明实际上不可能做到)以及状态栏中项目的不同布局。
子类UIWindow
:
@interface StatusBarMask : UIWindow
@end
@implementation StatusBarMask
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.windowLevel = UIWindowLevelStatusBar + 1.0f;
self.backgroundColor = [UIColor greenColor];
self.hidden = NO;
}
return self;
}
@end
以及实例化它的视图控制器:
@interface ViewController ()
@property (nonatomic, strong) StatusBarMask *mask;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect appStatusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
appStatusBarFrame.size.width = 384.0f;
appStatusBarFrame.origin.x = 384.0f;
self.mask = [[StatusBarMask alloc] initWithFrame:appStatusBarFrame];
}
@end
这将用亮绿色矩形遮住状态栏的右侧。根据需要调整颜色和大小,并考虑所有渐变、弯曲边缘等。通过仔细考虑各种边缘情况,您应该能够实现您的目标。
于 2012-10-04T22:18:36.623 回答
0
您可以使用以下代码隐藏顶部状态栏
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
于 2012-10-04T21:44:54.500 回答