UINavigationBar Custom Title View - iphone

I am using iOS 5 UINavigationBar's UIAppearance protocol in order to customise all my navigation bars.
Here is my customisation function:
- (void)customizeApperance
{
[[UINavigationBar appearance] setTintColor:[UIColor clearColor]];
[[UINavigationBar appearance] setAlpha:0.7];
UIImageView *titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"title.png"]];
[[UINavigationBar appearance] setTitleView:titleView];
}
I have two problems:
The first is that the colour not appearing as clearColor but black. Any suggestions?
The title view is not appearing at all. Ray Wenderlich shows how to do that by adding a: [[rootViewController navigationItem] setTitleView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"miniLogo.png"]]] in applicationDidFinishLaunching. But the problem with this is that the title view would only be added in the root view controller. I am using a UINavigationController and when I tired to replace the rootViewController with navigationController (the name of my navigation controller in AppDelegate), I cannot see the title view at all. How can I fix that? Why isn't it working in customizeApperance()? Isn't the whole point of using appearance is to just create a title view once (as I did above the function) and have it global in all navigation bars? How can I achieve that?

[UIColor clearColor] is a fully transparent color (alpha = 0). Setting that as tint color makes the (black) background shine through. Perhaps you want [UIColor whiteColor] ?
titleView is a property of UINavigationItem, and each view controller has it's own navigationItem. Therefore you cannot set a title view globally. But you can set the background image of UINavigationBar with the appearance protocol, perhaps that helps:
[[UINavigationBar appearance] setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

Have you tried titleView.opaque = NO;? If that's set to YES (i.e. by default, since you're using initWithImage:), the drawing system will assume your view fills its entire bounds, and won't bother drawing anything that overlaps its frame.

setTitleView: is a method on NavigationItem. But you are calling it on navigation bar

Related

ios7 UINavigationBar backgroundImage is set upside down

I am trying to set the UINavigationBar background image:
I added in AppDelegate: (please note that it's one image)
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"general-top_bar_with_status.png"] forBarMetrics:UIBarMetricsDefault];
Since I don't need translucent, in the ViewController in ViewDidLoad I added:
self.navigationController.navigationBar.translucent = NO;
This is the image:
Unfortunately this is what I get:
As you can see, the image is upsite down.
What is wrong?
In storyboard, I set a place for TopBar - Opaque navigation bar
For iOS 7 you have to use 320x64 size navigation bar image
make picture 2X Size. with name mynavbar#2x.png
Nav bar is Taking size of its self + status bar size. You may create only navbar size
640X88
or 640X128 for navbar + status bar
Then
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"mynavbar.png"] forBarMetrics:UIBarMetricsDefault];

iOS 7 UINavigationBar Background image hides Title view

I made iOS app, in which i want my app to compatible with iOS 7
Problem which i am facing is, when i run my app on iOS 7, Background image of my UINavigationBar hides my titleview and back button
:
-(void)viewDidLoad
{
[super viewDidLoad];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"top.png"] forBarMetrics:UIBarMetricsDefault];
self.title=#"Artist";
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
}
also when, i set Background image of UINavigationBar to nil it shows titleview and back button
When i run my apps prior to iOS 7 it works properly.
Please help.
Thanks in advance.
Behavior of tintColor for bars has changed on iOS 7.0, please check the image below:
You can see that
tintColor: is the color for the interactive elements within a navigation bar including button images and titles.
barTintColor is the background color of the UINavigationBar.
For your issue: you can do the below:
navigationBar.tintColor = [UIColor whiteColor];
navigationBar.barTintColor = [UIColor colorWithRed:6.0/255.0 green:12.0/255.0 blue:19.0/255.0 alpha:1.0];
The default font color is black so you are probably drawing a black font on a black background. Try the following:
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], NSForegroundColorAttributeName,nil]];
check the property extend edges on the property inspector of your view this will extend the edges from the bottom of your navigation bar to the top of your screen so your background image will be at the right place
check the transition guide for ios7 if you want more info about new things in ios7
https://developer.apple.com/library/prerelease/ios/documentation/UserExperience/Conceptual/TransitionGuide/index.html
following code worked for me
In viewDidLoad
self.navigationController.navigationBar.tintColor=[UIColor whiteColor];

Issue with UINavigationBar title alignment

I have an issue changing the font for the Title in my navigation controller.
Here is my code (from my subclass of UINavigationController):
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSDictionary * attributes = #{UITextAttributeTextColor :[UIColor whiteColor],
UITextAttributeFont :[UIFont fontWithName:#"Blanch" size:50],
};
self.navigationBar.titleTextAttributes = attributes;
CGFloat verticalOffset = -8;
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:verticalOffset forBarMetrics:UIBarMetricsDefault];
UIImage *image = [UIImage imageNamed:NAVBAR_IMAGE];
[self.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}
This is what it looks like:
If I comment out the line setting the font this is what it looks like (as expected with the vertical offset):
The only reason the vertical offset is there is that I thought it might have solved the problem. I don't need it and it is commented out now, but it does NOT change the output - it still looks the same just lower on the NavBar.
Any ideas how to solve this? I think it may be that the custom font has a lot of line-spacing
which I guess could be the problem.
I have been trying to find a way to change the origin/height/baseline alignment of the title but can't see a way to do any of these.
Any idea how to solve this problem ?
Create a container UIView which is the same width as your label, and height of UINavigationBar (around 46 pixels?). Set clipsToBounds on this container view to YES. Now add your label to this container view, and make the container view the titleView.
Setting Navigationbar image for ios5
if ([self.navigationController.navigationBar respondsToSelector:#selector( setBackgroundImage:forBarMetrics:)]){
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"YOUR_NAVIGATION_BAR_IMAGE"] forBarMetrics:UIBarMetricsDefault];
}
Setting Navigationbar image for ios6
if([[UINavigationBar appearance] respondsToSelector:#selector( setBackgroundImage:forBarMetrics:)]){
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"YOUR_NAVIGATION_BAR_IMAGE"] forBarMetrics:UIBarMetricsDefault];
after than create label in center on your navigation bar center with your title.

how to set image in more view controller's navigation bar and also change the colour of more label from white to green..?

I try to set image on navigation bar. when we pressed more button in tabbar..The default colour is blue.i wanna set image and chnge the colour of more label from white to green..Please help me
My code is given below, but it does not work
Appdelegte.m
tabMenu.moreNavigationController.navigationBar.tintColor = [UIColor colorWithPatternImage:[Uiimage imagewithnamed :#"nav.png"]];
tabMenu.moreNavigationController.delegate =self;
tabMenu.delegate = self;
You can do it like this :
[[[self.tabBarController moreNavigationController] navigationBar] setBackgroundImage:[UIImage imageNamed:#"myImage"] forBarMetrics:UIBarMetricsDefault];
However You can get instance of this "More" ViewController using...
UIViewController *moreViewController = tabBarController.moreNavigationController.topViewController;
moreViewController.view property contains UITableView and we can use it.
For example : To Add tableHeaderView :
UITableView *moreTableView = (UITableView*)moreViewController.view;
moreTableView.tableHeaderView = myOwnCustomView;
For more Reference you can check this Thread on Apple : moreNavigationController

How can I style an MKUserTrackingBarButtonItem?

I'm adding the items programatically, but MKUserTrackingBarButtonItem doesn't seem to offer any way to style it to fit in with a BlackTranslucent UIToolBar...
MKUserTrackingBarButtonItem is a subclass of UIBarButtonItem which has a tintColor property. You can use this to make your button black.
MKUserTrackingBarButtonItem *userTrackingBarButtonItem =
[[MKUserTrackingBarButtonItem alloc] initWithMapView:self.mapView];
[self.navigationController.toolbar setBarStyle:UIBarStyleBlack];
[userTrackingBarButtonItem setTintColor:[UIColor blackColor]];
If you do set it to black like this, the user will never know when it's activated, as the blue color is never shown.