2012-02-15 58 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]; 
相關問題