2017-03-28 17 views
7

ステータスバーの色を青色または他の色に変更しようとしています。ステータスバーの色を変更する

これは可能ですか、Appleは許可していませんか?

+1

2つの回答(コメント付き)に基づいて、(私が思ったように)答えは** no **です。 (1)ステータスバーのフォントの色を変更したり、(2)プライベートAPIを使用することはできますが、Appleがアプリケーションを拒否する(または悪化する)可能性があります。 – dfd

答えて

7

PLISTの最初の出力のスクリーンショットは、

enter image description here

+2

これは、アプリのレビューに合格しない、文書化されていないプライベートのAPIを使用しています。このようなことをすることは決して良い考えではありません。将来のiOSアップデートでプライベートAPIが変更されると、特に書面によるクラッシュが発生する可能性があります。 – rmaddy

+0

私は1つのアプリがこれを拒否されたが、もう1つはうまく受け入れられた。彼らはそれをプライベートAPIの使用と見なしますので、あなたは審査プロセス中に運が悪くなります:) - @Sebyddd – byJeevan

+0

私は間違いなく**この**事実をあなたの答えに追加します。 – dfd

6

を下回っているNO

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
    // Override point for customization after application launch. 

    let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView 
    if statusBar.responds(to:#selector(setter: UIView.backgroundColor)) { 
     statusBar.backgroundColor = UIColor.blue 
    } 
    UIApplication.shared.statusBarStyle = .lightContent 

    return true 
} 

View controller-based status bar appearanceを設定しません、それは既製のパブリックAPIとはできません。

しかし、iOS 7のリリースでは、ステータスバーの外観を変更することができます。したがって私はここで私の回避策を投稿しています。

preferredStatusBarStyleをオーバーライドすることにより、個々のビューコントローラから:

-(UIStatusBarStyle)preferredStatusBarStyle 
{ 
    return UIStatusBarStyleLightContent; 
} 

を別の方法として、あなたはUIApplication statusBarStyleメソッドを使用して、ステータスバーのスタイルを設定することができます。これを行うには、「コントローラベースのステータスバー表示の表示」という名前の新しいキーを挿入し、値をNOに設定します。 enter image description here

"コントローラベースのステータスバーの表示"を無効にすると、次のコードを使用してステータスバーのスタイルを設定できます。終わり

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; 

、あなたはアプリケーションの起動中に、またはあなたのビューコントローラののviewDidLoad中にステータスバーの背景色を設定することができます

[[UINavigationBar appearance] setBarTintColor:[UIColor blueColor]]; 

以下
+0

回答を明確にするには、ステータスバー**背景**の色を**特定の**色に変更しますか? – dfd

+0

この編集は理にかなっていません。オペレータは、ナビゲーションバーではなく、ステータスバーを変更する必要があります。 – dfd

+0

このリンクを参考にしてください。http://www.appcoda.com/customize-navigation-status-bar-ios-7/ – byJeevan

3


ようUINavigationBar財産色合いの色を変更します。ここで

enter image description here

は、ステータスバーの変更についてApple Guidelines/Instructionである:ここで

extension UIApplication { 

    var statusBarView: UIView? { 
     return value(forKey: "statusBar") as? UIView 
    } 

} 

// Set upon application launch, if you've application based status bar 
class AppDelegate: UIResponder, UIApplicationDelegate { 

    var window: UIWindow? 

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
     UIApplication.shared.statusBarView?.backgroundColor = UIColor.red 
     return true 
    } 
} 


or 
// Set it from your view controller if you've view controller based statusbar 
class ViewController: UIViewController { 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     UIApplication.shared.statusBarView?.backgroundColor = UIColor.red 
    } 

} 



は結果です。ステータスバーに暗い&ライト(&黒)が許可されています。ここで

がある - ステータスバーのスタイルを変更する方法:あなたは、ステータスバーのスタイルを設定したい場合は

、アプリケーションレベルでは、あなたの `の.plist」ファイルにNOUIViewControllerBasedStatusBarAppearanceを設定します。

あなたは、ビューコントローラレベルで、ステータスバーのスタイルを設定するワンならば、次の手順を実行します。あなただけのUIViewControllerレベルでのステータスバーのスタイルを設定する必要がある場合は、.plistファイルにYESからUIViewControllerBasedStatusBarAppearanceを設定

  1. を。あなたのビューコントローラにsetNeedsStatusBarAppearanceUpdate

  2. オーバーライドpreferredStatusBarStyle - のviewDidLoadで

  3. は、機能を追加します。

-

override func viewDidLoad() { 
    super.viewDidLoad() 
    self.setNeedsStatusBarAppearanceUpdate() 
} 

override var preferredStatusBarStyle: UIStatusBarStyle { 
    return .lightContent 
} 

の.plistの設定値、ステータスバーのスタイルの設定レベルに応じました。 enter image description here

2

ここでは私の回避策です:1.Create
人工ステータスバーの背景としてビューコントローラのルートビューに追加し、UIViewを作成UIView

// status bar's height is 20.0pt 
CGRect frame = CGRectMake(0.0, 0.0, [UIScreen mainScreen].bounds.size.width, 20.0); 
UIView *fakeStatusBarBG = [[UIView alloc] initWithFrame:frame]; 
fakeStatusBarBG.backgroundColor = [UIColor yourColor]; 

2.Addそれにあなたのビューコントローラのルートビュー

// self is your view controller, make sure fakeStatusBarBG is the top subview in your view hierarchy 
[self.view insertSubview:fakeStatusBarBG aboveSubview:yourTopSubview]; 

あなたが行ってください。

3.(追加)ステータスバーのコンテンツの色を白または黒のみに変更します。

​​

この回避策ではプライベートAPIを使用しないため、安全です。 :-)