iOS(Status Bar)を非表示にする
iOSでStatus Bar を非表示にする方法です。
時間とか, ネットワークのloading iconとか, キャリアとかの情報が表示されます。20px分の幅があります。
iOS7ではこの部分が, 透明になって他のUIをオーバーラップできることで, iOS6.1とのCompatibleで問題になったりします。
このStatus Barをいっそのこと非表示にしてしまえば20px分有効活用できるというわけです。
方法としては, 2つあげておきます。
- Info.plistで設定
- コードで設定
筆者は, xibでViewをつくる方法で試した結果, 1でうまくいきました。stackoverflowやほかのWebサイトでは2なども試しているもの見受けられました。2ではiOS7がうまくいきませんでした。
Info.plistで設定
Status bar is initially hidden, View controller-based status bar appearanceというプロパティを追加します。
それぞれ, YES, NO にします。
Info.plistの変更の詳細は割愛します。
Property name | iOS | Value |
---|---|---|
Status bar is initially hidden | iOS6.1以下 | YES |
View controller-based status bar appearance | iOS7以降 | NO |
はい, この設定だけで, すべてのViewControllerに適用されます。
コード
確かに以前はこの方法でやっていました。
ViewControllerのprefersStatusBarHiddenというメソッドをOverrideします。
そして, 以下のコードを入れて, statusbar のupdateをかけます
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) { // iOS 7 [self prefersStatusBarHidden]; [self setNeedsStatusBarAppearanceUpdate]; } else { // iOS 6 [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide]; } - (BOOL)prefersStatusBarHidden { return YES; }
以上のコードをViewControllerにいれます。setNeedsStatusBarAppearanceUpdateというのがiOS7以降のstatusbarの
アップデーをかけるメソッドです。
Greetings!Very useful advice in this particular post!
It’s the little changes that will make the greatest changes.
Thanks a lot for sharing!
There’s certainly a lot to learn about this subject.
I love all of the points you have made.
I wanted to thank you for this very good read!! I absolutely lved evbery
little bit of it. I have got you book-marked to look at
new things you post…
This is a extremely excellent report, I think there will be several folks. like it, of system, I was 1 of the individuals. I consider this write-up. improve my understanding. Thank you!
Youa??re so awesome! I dona??t believe I have read through anything like this before. So great to uncover any person with some original ideas on this subject matter. Many thanks for starting this up. tava tea
I think this is truly basically the most critical information individually. And i’m content studying the submit. Nevertheless must statement on couple of simple points, The internet world wide web website style is perfect, the actual material content articles is really exceptional : Deb. Outstanding task, cheers
Howdy! I just wish to offer you a big thumbs up for your excellent information you have right here oon this post.
I will be returning to your site for more soon.
Great, thanks for sharing this blog.Thanks Again. Will read on…
Ahaa, its pleasant conversation on the topi of this piece of writing
at this place at this weblog, I have read all that,
so at this time me also commenting here.
I am sure this piece of writing has touched all the internet viewers, its really really
nice post on building up new website.
Great work! That is the type of info that are meant to be shared around the internet.
Shame on the seek engines for now not positioning this
submit upper! Come on over and discuss with my website .
Thanks =)
Thanks designed for sharing such a fastidious thinking, article is fastidious, thats why i have read it entirely
These are in fact impressive ideas in concerning blogging.
You have touched some pleasant points here. Any way keep up wrinting.
Ahaa, its nice conversation about this post at this place at this webpage, I have read all that,
so now me also commenting here.
I simply want to mention I am new to blogs and seriously loved you’re web blog. Likely I’m likely to bookmark your blog post . You amazingly come with fantastic writings. Cheers for sharing with us your web-site.