Navigation bar and Status bar issue in iOS 7 - iphone

I have created an application using XIB without Status Bar before for iOS7, now i need to add Status bar on my app and Status bar background color should same as Navigation bar background color. So i have tried like (In my info.plist) :
1) Set View controller-based status bar appearance to NO
2) Set Status bar style to UIStatusBarStyleLightContent
here is my code for App Delegate:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
[[UINavigationBar appearance] setBarStyle:UIBarStyleDefault];
[[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithRed:(51/255.0) green:(51/255.0) blue:(51/255.0) alpha:1.0]];
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:(51/255.0) green:(51/255.0) blue:(51/255.0) alpha:1.0]];
So i am getting the output like the below image :
also i am getting misplacement of UIButtons that i have given below in my screen (It's hiding 20 pixels).
Can you please help me that how can i fix this issue? I need my output like the below image :
Any help will be very appreciated, Thanks.
Third screen :

Add following code in your viewDidLoad method :
float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
if (systemVersion >= 7.0)
{
self.edgesForExtendedLayout = UIRectEdgeNone;
}

Please define this in AppDelegate.h (or) constants.h
#define isIOS7 ([[[UIDevice currentDevice]systemVersion]floatValue] >=7.0)?YES:NO
under viewDidLoad Write this lines.
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 320, 20);
addStatusBar.backgroundColor = [UIColor colorWithRed:0.973 green:0.973 blue:0.973 alpha:1];
//change this to match your navigation bar
[self.window.rootViewController.view addSubview:addStatusBar];
}
OR we can change it manually in the xib.
By moving each element 20px down.

Surprise at how few people have suggested this. Here is the correct way (no hacking)
First, make your navigationBar have a Y origin of 20.
Then in the .h file, set your ViewController as a UIBarPositioningDelegate:
#interface XYZViewController : UIViewController <UIBarPositioningDelegate>
And in the .m file:
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationBar.delegate = self;
}
- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar {
return UIBarPositionTopAttached;
}

Related

status bar issue while presenting model view controller in ios 7

I have returned in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
RootViewController *rvc = [[[RootViewController alloc] init] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:rvc] autorelease];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}
View controller-based status bar appearance is YES in plist file
when i am pushing view controllers status bar is looking great. As showing in following image.
but when i am presenting modelviewcontroller it look as following.
I have written following code in viewDidLoad method of viewcontroller which I am presenting
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
// iOS 7
navBar.frame = CGRectMake(navBar.frame.origin.x, 20, navBar.frame.size.width, 44);
}
I want to display black status bar when presentingmodelview. But it is not displaying.
I tried with
View controller-based status bar appearance is NO also in plist file
but it is not working.
My code is working great in all ios version below 7.0 but not in ios 7.0 and above.
Any solution for this ? Let me know if any one not getting my question.
Good solution found in this question .
1) Set UIViewControllerBasedStatusBarAppearance to NO in info.plist (To opt out of having view controllers adjust the status bar style so that we can set the status bar style by using the UIApplicationstatusBarStyle method.)
2) In AppDelegate's application:didFinishLaunchingWithOptions, call
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
[application setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.clipsToBounds =YES;
self.window.frame = CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
self.window.bounds = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height);
}
return YES;

iOS 7 staus bar issues

I have an application with status bar hidden. For hiding status bar I did following things:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
This was working with ios 6. Now in iOS 7 I added View controller-based status bar appearance = NO.
I also created subclass of my navigation controller and added:
- (BOOL)prefersStatusBarHidden
{
return YES;
}
Everything is working well but when I present UIImagePicker status bar goes visible and than it never hides back even after dismissing view. I also added prefersStatusBarHidden method in the related view too but no success :(
Any help please.
Use following link
- (void)imagePickerController:(UIImagePickerController *)aPicker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// for iOS7
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)]) {
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
Following are the list of reference regarding status bar issues in ios7 on stack overflow Itself. ;-)
Status bar and navigation bar appear over my view's bounds in iOS 7
Status bar won't disappear
Status bar appear over my view's bounds in iOS 7
Use can use this method for status bar Issue.It should work fine.
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 320, 20);
addStatusBar.backgroundColor = [UIColor colorWithRed:0.973 green:0.973 blue:0.973 alpha:1]; //change this to match your navigation bar
[self.window.rootViewController.view addSubview:addStatusBar];
}
Try this in your Target's general settings.

Set titleview for all navigationcontroller and navigationitem

[[[UINavigationBar appearance] setTitleView:button]
I tried to set title view as button for all navigation item using above line of code but it is not working.How can I set title view for all navigation bars in my project by writing small code in appdelegate ?
Customizing the Appearance of a Navigation Bar
it is alright to modify the barStyle, tintColor, and translucent
properties, but you must never directly change UIView-level properties
such as the frame, bounds, alpha, or hidden properties directly.
For more detail you can follow apple doc UINavigationBar Class Reference
Edit ->
I solved your query
[[UINavigationBar appearance] addSubview:yourView];
Other Navigation Related query
try this dude...
//put whatever object in this view..for example button that you want to put...
UIView* ctrl = [[UIView alloc] initWithFrame:navController.navigationBar.bounds];
ctrl.backgroundColor = [UIColor yellowColor];
ctrl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[navController.navigationBar addSubview:ctrl];
let me know it is working or not!!!!
Happy Coding!!!
This is how you create a navigation controller in addDelegate and set a title to it,
you have to add the following code to didFinishLaunchingWithOptions method.
Notice that you need to set a root view for the viewController which will the viewController that will be displayed inside the navigationController.
yourViewController *mainVC = [[yourViewController alloc]init];
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:mainVC];
navigationController1.title = #"title";
[window addSubview:navigationController1.view];
If you use iOS4, you can override drawRect
#implementation UINavigationBar (UINavigationBarCategory)
-(void)drawRect:(CGRect)rect
{
UIImageView *itleImageView = //create object
[self addSubView:titleImageView];
//set title view in navigation bar
}
#end
iOS 5,
if ([[UIDevice currentDevice].systemVersion floatValue] >= 5.0) {
if ([self.navigationController.navigationBar respondsToSelector:#selector( setBackgroundImage:forBarMetrics:)]){
UIImageView *itleImageView = //create object
[self.navigationController.navigationBar addSubView:titleImageView];
}
}
i guess this is a right, as i don't have implemented.
I wanted to add a logo in every NavigationController, so I made a subclass of
UINavigationController and used this in the viewDidLoad-Method
UIImage *logo =[UIImage imageNamed:#"logo"];
CGFloat navWidth = self.navigationBar.frame.size.width;
CGFloat navHeight = self.navigationBar.frame.size.height;
UIImageView *logoView = [[UIImageView alloc] initWithFrame:CGRectMake(navWidth-logo.size.width - 5,
(navHeight - logo.size.height) / 2,
logo.size.width,
logo.size.height)];
logoView.image = logo;
[self.navigationBar addSubview:logoView];

ios : how to remove the white space bar above navigation bar?

For Customing navigation bar, I want set the background image and custom the left button and right button.so I instance it with code without .xib. but there is a white space bar above navigation bar.
here is my code :
-(void) createNavBar:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options
{
if (!navBar)
{
navBarController = [[[UINavigationController alloc] init] autorelease];
navBarController.navigationBar.bounds = CGRectMake(0, 0, 320, 40);
[navBarController.navigationBar setBackgroundImage:[UIImage imageNamed:#"www/images/header_bg#2x.png"] forBarMetrics:UIBarMetricsDefault];
[[[self webView] superview] addSubview: navBarController.navigationBar];
}
}
run and build, find there is a white space bar above navigation bar.
here is a Screenshot:
How can remove the space bar between the title bar and the blue navigation bar?
Thanks for your guide.
In Xib check your view and webView Y and height
Try using this:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
That worked for me.
insert [self.navigationController.navigationBar.layer setMasksToBounds:NO]; in viewDidLoad

ios5.1 adding a UIView on top of iphone statusbar

I am trying to add a view on top of the statusbar. I have been following this SO post: Adding view on StatusBar in iPhone
For some reason, when I create the window and set Hidden to NO, the view does not appear to show up on top of the statusbar. Does this implementation still work in ios5.1?
Thanks!
This is my custom UIWindow class:
#implementation StatusBarOverlay
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Place the window on the correct level and position
self.hidden = NO;
self.windowLevel = UIWindowLevelStatusBar+1.0f;
self.frame = [[UIApplication sharedApplication] statusBarFrame];
// Create an image view with an image to make it look like a status bar.
UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:self.frame];
backgroundImageView.image = [UIImage imageNamed:#"bar_0.png"];
backgroundImageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:#"bar_1.png"],
[UIImage imageNamed:#"bar_2.png"],
[UIImage imageNamed:#"bar_3.png"],
nil];
backgroundImageView.animationDuration = 0.8;
[backgroundImageView startAnimating];
[self addSubview:backgroundImageView];
}
return self;
}
In my viewcontroller, I created the new window and called this in viewDidLoad:
StatusBarOverlay *overlayWindow = [[StatusBarOverlay alloc] initWithFrame:CGRectZero];
[overlayWindow makeKeyAndVisible];
However, the view still doesn't show up. Any idea as to why?
set your application's window level to UIWindowLevelStatusBar:
self.window.windowLevel = UIWindowLevelStatusBar;
and then add your own view to application window anywhere:
[[[UIApplication sharedApplication]delegate].window addSubview:yourview];
this problem came to me recently, and I just solved it through this way
You can create a new UIWindow and add your view to that. Set the windows frame to [[UIApplication sharedApplication] statusBarFrame] and call makeKeyAndVisible to make it visible.
In the end, I subclassed UIWindow and made that the primary UIWindow in the application AppDelegate. I added any custom view and set the window level to UIWindowLevelStatusBar to display on top of the status bar.