IOS 6 navigationController navigationbar - objective-c

I just updated my phone to IOS 6 but I have some issue regarding adding UIImageView on the UINavigationController navigationbar. This is my code
UIImage *logoImage = [UIImage imageNamed:#"navigationbar.png"];
UIImageView *logoImageView = [[UIImageView alloc] initWithImage:logoImage];
UINavigationBar *navBar = self.navigationController.navigationBar;
[navBar addSubview:logoImageView];
[logoImageView release];
This will add logo on navigationbar, it works great on the lower version of IOS 6. But on IOS 6 the logo shown but the back button was behind the logo so back button is not shown.
I don't want to override the UINavigationBar drawrect since I also have UINavigatioBar somewhere on the code for popup.
Any suggestions?

I think you don't need a UIImageView in IOS 6.
You can just put a background image in the UINavigationBar (for example in AppDelegate) like this:
[[UINavigationBar appearance] setBackgroundImage :[UIImage imageNamed:#"navigationbar"]];
Found a good site which explains some new user interface customisation in IOS 6:
click here

Related

iOS 9: Background Image for UINavigationBar not working

I have a global background image (basically some orange color) which is set for all navigation bars inside the AppDelegate:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"order-navbar"] forBarMetrics:UIBarMetricsDefault];
This works for all views except one: I have an MFMailComposeViewController whose navigation bar background stays white-gray no matter what I do:
let mailController = MFMailComposeViewController()
mailController.navigationBar.tintColor = UIColor.whiteColor() // this works
emailController.navigationBar.setBackgroundImage(UIImage(named: "order-navbar") forBarMetrics:UIBarMetrics.Default) // this does not
UINavigationBar.appearance().setBackgroundImage(UIImage(named: "order-navbar") forBarMetrics:UIBarMetrics.Default) // this does neither
However, sometimes the mail controller appears at first with the orange bar and then suddenly changes its color to white-gray again.
On iOS 8 everything works. Is this an iOS 9 bug?

UINavigationController in UITabBarController: NavigationItems disappear in iOS7

I have an iPad application compatible with iOS 5.1 or higher. I'm updating the app for iOS 7.
I have this problem: I have a UINavigationController inside a UITabBarController. I want to add rightBarButtonItems. With iOS 6 or lower are seen, but with iOS 7 no. What I'm wrong?
PS: I'm forced to make app compatible with iOS 5.1 because there are some customers who are still using the first generation of iPad, so I can't use AutoLayout. I'm XIB because the project is a pretty old and I haven't to rewrite code.
Thank you!!
edit for Nikos M.
self.navigationItem.rightBarButtonItems = #[...];
Image: http://i.stack.imgur.com/RB3Rc.png
Edit 2:
I had tried to add a custom view on navigation bar:
//I added this line otherwise I not see the Navigation Bar!!
[self.navigationController.navigationBar setFrame:CGRectMake(0, 0, 320, 132)];
[self.navigationController.navigationBar addSubview:[self addTableHeader]];
and this is the result!!
http://i.stack.imgur.com/aksqb.png
This is working for me in iOS 7. Try this.
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:[[UIBarButtonItem alloc]initWithTitle:#"ONE" style:UIBarButtonItemStylePlain target:self action:nil], nil];

Navigation controller affecting app overall background image

I have an application where when it begins, it loads a viewController which loads the Default.png launch image and holds it there for 1.5 seconds, then that image fades out, then fades into another image which will be the background image for my entire application. From here it loads the first viewController and then the buttons and navigation bar fade in.
So it goes SplashScreeVC - Default.png presented
Default.png Fades out
New Image fades in (This is the apps overall background image)
Loads MainVC with buttons and nav bar alpha set to 0.1.
Method called to fade in the nav bar and the buttons in the mainVC
So in my app Delegate I have this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
SplashVC *splash = [[SplashVC alloc] initWithNibName:#"SplashView" bundle:nil];
self.window.rootViewController = splash;
[self.window makeKeyAndVisible];
return YES;
}
So the app loads with the Default.png, which then loads the splashVC which has the Default.png as its background image, this is shown for 1.5 seconds. I then have a some methods to fade out this image, and then fade in the image that will be used as the background image for the entire application. Then it calls the appDelegates MainNav method which loads the Navigation controller. The app Delegates MainNav method is below
-(void) MainNav
{
UIViewController *main = [[MainVC alloc] initWithNibName:#"MainView" bundle:nil];
self.navController = [[UINavigationController alloc] initWithRootViewController:main];
UIImage *navImage = [UIImage imageNamed:#"NavBarGrey.png"];
//Add the custom image
[[self.navController navigationBar] setBackgroundImage:navImage forBarMetrics:UIBarMetricsDefault];
//[[UINavigationBar appearance] setTintColor:UIColorFromRGB(0xee2e24)];
[[UINavigationBar appearance] setTintColor:UIColorFromRGB(0xe7e7e7)];
self.navController.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"backgroundImage.png"]];
self.window.rootViewController = self.navController;
}
The problem is when it moves from the SplashScreen VC to the MainVC, the image suddenly jerks up despite the fact it is the same image that fades in in the SplashVC.
Does anyone have any idea why this is? I am guessing it has something to do with the navigation controller affecting the image size, but not sure what to do to fix it? Do I need to create a new image for the navigation bar background with different dimensions? Or is there another way I can fix this issue?
Any advice would be much appreciated. Thanks!!
Edit: Fixed image jerking to the right, had image width at wrong height, but the image is still jumping up a set amount
Managed to figure it out. Seems to have to make a copy of the image and increase its height by 20 pixels and set that as the navigation bars background image. This offsets the navigation bar problem.
you can set bacround image code like
yourView.setBacroundColur=[UIColour colourWithImagePttern:[UIImage ImageNamed:#""]];

UINavigationBar tint color flashing in iOS 4

The app I'm working on has a custom nab bar but supports iOS 4.2-iOS 5, so I need to set the UINavigationBar background and tint in this old school way in my app delegate.
#implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
self.tintColor = [UIColor colorWithRed:42.0/255.0
green:164.0/255.0
blue:182.0/255.0
alpha:1.0];
UIImage *img = [UIImage imageNamed:#"navbar_bg.png"];
[img drawInRect:CGRectMake(0.0, 0.0,
self.frame.size.width,
self.frame.size.height)];
}
#end
This works for the most part, but I noticed when the app is first starting, the UIBarButtonItems flash the default navigation bar color for a second before they correct themselves and change color to match the navigation bar. Interestingly, the navigation bar itself uses the background image correctly from the get-go.
To be clear, I'm using setBackgroundImage for UINavigationBar on iOS 5 devices which works as expected so the flash is only in iOS 4.
Anyone have any insight on why this would happen and/or how to fix it?
The bar button items are the wrong color? You can manually set their tint color in viewDidLoad: to the tint color
navigationBar.rightBarButtonItem.tintColor = [UIColor ...]
if you're using a nib file. Otherwise you can do the same thing in loadView: . Either way this code will get executed as part of the initial draw loop so you'll have the proper color without any flashing.
Also for future reference, it's technically incorrect to override a method inside a category. (The latest version of Xcode, 4.3, will give you a warning about this). You should either properly subclass UINavigationBar or do "method swizzling". But that's pretty tough so don't worry about it right now :)
If you call the class with the code referenced in viewDidLoad try moving it to awakeFromNib

MPMoviePlayerViewController customization

I'm using MPMoviePlayerViewController - with the player controls set to: MPMovieControlStyleFullscreen
I'm having a problem with some of buttons that are in MPMovieControlStyleFullscreen: forward, reverse, and fullscreen (the one with the arrows pointing at eachother).
I would like to either remove the forward, reverse, and fullscreen buttons or control what they do when the user taps them.
Thank you!
There isn't a way to customize the MPMovieControlStyle values provided by Apple. What you need to do is is turn off the Apple controls (MPMovieControlStyleNone) and then create your own custom controls. Apple is fine with you putting your own UIViews in to the hierarchy here, so you can get started with something like this:
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: YOUR_URL];
moviePlayer.controlStyle = MPMovieControlStyleNone;
UIView *movieView = moviePlayer.view;
[movieView addSubview: _movieControlsView];
[movieView bringSubviewToFront: _movieControlsView];
Where _movieControlsView was set up earlier in code or in IB.
Aesthetically, you can do what you want, but I would recommend sticking with something that looks like Apple's choices so as not to confuse the user. For the project I just finished, I created a transparent button the exact size of the movie player. Clicking the button fades in a control bar on the bottom with my custom controls. If one of the controls isn't clicked, the control bar fades back out again after a few seconds.
First off, MPMoviePlayerController is a little different than MPMoviePlayer*View*Controller, so some of these answers lead to problems when converting applications that were built in an iOS 4.3+ environment.
I've built some apps using MPMoviePlayerController that worked fine when built in iOS 3.2. When I rebuilt it with XCode 3.2.6, (iOS 4.3), the videos don't even play on the iPhone. I since fixed that by adding the MPMoviePlayerController instance to a subView, then presenting a modal (Player is a UIViewController) with the movplayer in fullScreenMode:
//from didSelectRowAtIndexPath
Vid *selected = [items objectAtIndex:position];
player = [[Player alloc] init];
movplayer = [[MPMoviePlayerController alloc] initWithContentURL:selected.vidURL];
movplayer.view.frame = player.view.bounds;
movplayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
[player.view addSubview:movplayer.view];
[self presentModalViewController:player animated:YES];
[movplayer setFullscreen:YES animated:NO];
[movplayer play];
[player release];
//movplayer is released inside - (void)exitedFullscreen:(NSNotification*)notification
This was done on account of the UINavigationBar being half cut off when rotating.
When I got to the iPad version of the app the modal option wouldn't work aesthetically. It was also having the UISplitViewController navBar and toolbars half cut off when rotating in full screen mode. So I tried implementing MPMoviePlayerViewController instead of MPMoviePlayerController. With this conversion, XCode gave me errors when trying to set:
movplayer.controlStyle = MPMovieControlStyleEmbedded;
The proper way to do this with a MPMoviePlayerViewController is:
movplayer.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
When the player is added as a subView, the pinch gestures will toggle the player between fullScreen and the size of your parentView (player.view.bounds) smoothly, as well as preserve the toolbars and navBars native to the parent.
//iPad version with a view (viewForMovie) inside the DetailViewController
movplayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[current vidURL]];
movplayer.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
movplayer.view.backgroundColor = [UIColor clearColor];
movplayer.view.frame = viewForMovie.bounds;
[viewForMovie addSubview:movplayer.view];
So these two examples show some workarounds for those who want to convert their iPhone or iPad apps to a newer iOS version.
Try setting MPMovieControlStyle of your MPMoviePlayerController object to MPMovieControlStyleNone