5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

2色の相対から自動的にステータスバーの色を選出

Posted at

iOS7からステータスバーがちょっとオシャレになりました。
が、結局色は白と黒の2色しか選べません。
またiOS6以前と違い背景色が黒でステータスバーも黒とかにするとステータスバーが見えなくなって良くない感じです。
色を決め打ちで開発する場合は問題ないですが、UIのカラーをユーザが自由に設定出来る場合はステータスバーの色もユーザに指定させるよりもアプリ側で自動選出する方がスマートです。
以下のように実装することで2色から見やすいステータスバーの色を選出することが出来ます。

-(UIStatusBarStyle)statusbarstyleWithBaseColor:(UIColor*)baseColor ButtonColor:(UIColor*)buttonColor{
    CGFloat b1,b2;
    [baseColor   getHue:nil saturation:nil brightness:&b1 alpha:nil];
    [buttonColor getHue:nil saturation:nil brightness:&b2 alpha:nil];
    return b1>b2?UIStatusBarStyleLightContent:UIStatusBarStyleDefault;
}

UInavigationbarの色とUIBarbuttonの色の関係から選出するといい感じかもしれないですね。

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?