2012-02-15 61 views
1

我想添加一个按钮或在iPhone的状态栏上的任何自定义视图,如何在状态栏上添加按钮或任何视图?

如果苹果不允许自定义状态栏比它可以通过状态栏添加任何按钮或视图...

有没有人有关于此的想法请与我分享。

感谢,

+0

我的任何一个回答将有助于全给我也 – 2012-02-15 05:21:09

+2

这个SO后可以帮助你http://stackoverflow.com/questions/2833724/adding-view -on-statusbar-in-iphone – Maulik 2012-02-15 05:42:42

+0

谢谢Maulik ...我得到它我想要的任何东西.. :) – Raj 2012-02-15 06:06:06

回答

1

可以隐藏默认的状态栏,并创建一个具有相同高度的状态栏自定义栏,并在视图中显示它。除了改变颜色(灰色/黑色),不透明(不透明/半透明)和可视性(隐藏/可见)之外,Apple不允许您自定义状态栏。

+0

好吧但它是否可以添加任何事件状态bur? – Raj 2012-02-15 05:39:27

+0

哪类事件? – 2012-02-15 05:41:41

+0

例如触摸事件... – Raj 2012-02-15 05:46:38

1
[[UIApplication sharedApplication]setStatusBarHidden:YES withAnimation:NO]; 

// Create window 
UIWindow *statusWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0,0,320,20)]; 
statusWindow.windowLevel = UIWindowLevelStatusBar; 
statusWindow.backgroundColor=[UIColor redColor]; 

// Dont make the statusWindow keyWindow or the keyboard won't work! 
// [statusWindow makeKeyAndVisible]; 

// Create statusBarButton 
UIButton *statusBarButton = [UIButton buttonWithType:UIButtonTypeContactAdd]; 

statusBarButton.frame = CGRectMake(230, 2, 15, 15); 
statusBarButton.backgroundColor=[UIColor redColor]; 
[statusBarButton addTarget:self action:@selector(goTop) forControlEvents:UIControlEventTouchUpInside]; 

// Place button into the new window 

    // Instead, add this: 
[self.window makeKeyAndVisible]; // has to be main window of app 
statusWindow.hidden = NO; 

[statusWindow addSubview:statusBarButton]; 
1

一个好主意

UIWindow *statusWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0,0,320,20)]; 
statusWindow.windowLevel = UIWindowLevelStatusBar; 
statusWindow.backgroundColor=[UIColor redColor]; 
相关问题