Write some text in (or on) UIStatusBar - iphone

I know, it's a strange question ^^,
I would like to know if there is a way to write some text in (or on) the UIStatusBar. In particular I want to write some text on the Status Bar when the user press a UIButton.
Thanks!

I'm not sure if you can draw directly into the status bar, but you should be able to draw on top of it in a custom view. You can get the status bar's frame using:
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
And you can get the application's main window (presumably the status bar's superview) using:
UIWindow *mainWindow = [[UIApplication sharedApplication] keyWindow];
You should be able to add your custom view directly to the key window in the status bar's frame. For an example of an app that appears to "modify" the status bar, take a look at Reeder.

No, the status bar is a system-controlled element. It's content cannot be modified by a third-party application.

Check out this work in progress: https://github.com/maciekish/APStatusBarExtensions

MTStatusBarOverlay is what you want :
https://github.com/myell0w/MTStatusBarOverlay
Definitely the easier to use !

Related

Is it possible to overlap the status bar with content in iOS?

Is it possible for content in a view to overlap the status bar in iOS? I don't want to cover the whole status bar - just have a graphic extend a few pixels into it.
Are there any examples of this in the store now? Or does the HIG prohibit it?
I've seen examples of apps that place their own content in the iOS status bar. Reeder is perhaps the most popular example of this. But in Reeder, the content is contained entirely within the status bar.
You can use UIWindow,
UIApplication *app = [UIApplication sharedApplication];
UIWindow *overlapView = [UIWindow new];
overlapView.windowLevel = UIWindowLevelStatusBar + 1;
overlapView.frame = app.statusBarFrame; // you can set any size of frame you want
P.S. instance of UIWindow is set hidden = YES by default, so you should set hidden = NO when you want to display the overlapView;

How to get a black status bar on an iPhone app?

I want to use a black status bar for my iPhone app. I have selected black status bar on all of my .xibs but I still can't get it to be black. Is this an issue that anyone else has seen or knows how to remedy?
Open the "info.plist" file .
Add a new row.
Select "Status bar style" as the key.
Select "Opaque black style" as the value.
EDIT: The comment by #codrut below to choose the value:
If you go far to the right, there's a button that brings you a drop down with the possible options.
The status bar in the nib files is there as an indication, just to simulate the real interface.
What you need to do is:
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque];
and in the plist change the Status Bar Style (UIStatusBarStyle) to Black opaque (UIStatusBarStyleBlackOpaque) (or whatever you want).
Add the following in the info.plist file
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleBlackOpaque</string>
Not sure if this will help anyone else, but in our app we ran into an issue where the only way we could get it to use the black style was if we set it to the default style:
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleDefault];
Might be worth giving that a try if BlackOpaque isn't working for you.
Try this simple method....
1.For single viewController
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque];
2.For whole application
info.plist
----> Status Bar Style
--->UIStatusBarStyle to UIStatusBarStyleBlackOpaque

creating new view in iPhone application

i just finished my first view in my iPhone app and i want to add a second view to wich the user go when he click in the button in the first view. So i add new view from the librairy window, but i don't see the battery in the top, is that normal ? and how to add it please ??
Assuming you mean the status bar along the top you can try this code to make sure it is shown:
[[UIApplication sharedApplication] setStatusBarHidden:NO];
or:
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
if you want to animate it coming down.
Cheers.

How to the grab the highest level Superview in iPhone App?

I want to be able to grab the main UIView for the application. So far, I have been calling [[[self.view superview] superview] superview] to traverse up the chain (or down, depending on how you look at it). The problem with this is that it is possible that I can't be absolutely sure the number of levels up I need to go. Is there a way to:
Go directly to the highest level UIView in an iPhone application?
or, if not,
Check to see if the current superview is the highest level UIView in the app?
I'm not sure that it's what your are looking for in the first place, but it can help.
If you are trying to find the top view in order to add a subview, like say a popup or other, you can use UIWindow, which is in some way, the top level view:
UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window) {
window = [[UIApplication sharedApplication].windows objectAtIndex:0];
}
[window addSubview:yourView];
Just pulling this off the top, something like checking if the superview property of the current view is null? If it is I guess we may presume that it is the root view.

Hiding status bar completely

I hide the status bar in applicationDidFinishLaunching using
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
That works fine except the status bar is there while the app is loading. Meaning, when the default.png is displayed, I see the status bar. Is there a way to have the status bar not show at all?
Add UIStatusBarHidden to your info.plist file, set to true. Documentation here:
http://developer.apple.com/library/ios/ipad/#documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html
You need to use this:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
and then open up the info.plist file, create a new line, chose Status bar is initial hidden and set it to true.
You need to edit your Info.plist to include the entry "Status bar is initially hidden" and set the value to YES.
For more information:
http://www.idev101.com/code/User_Interface/StatusBar.html