iOS Image in navigation Item titleview - ios

I want to add an image in my navigation bar. To do this, i wrote that :
self.navigationItem.titleView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:#"logo.png"]];
It's running, but the only problem is the image seems to be blurred.
When i look it on photoshop or other software, the image is perfect.
The size of this image is : 120 x 30px.
Someone to help me ? Thx

First of all, please, print self.navigationItem.titleView.frame after your viewDidAppear.
Seems to be, that in some case your titleView is placed with half-pixeled origin.x, or origin.y.
Try to play with:
[self.navigationController.navigationBar setTitleVerticalPositionAdjustment:<#(CGFloat)#> forBarMetrics:<#(UIBarMetrics)#>]
Try to set different values to the first param and observe the result.

You can change the navigation and status bar background only in iOS7. For this, you can use
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"yourImage.png"] forBarMetrics:UIBarMetricsDefault];
The size should be 320*64 px
and to change the Navigation Bar title
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"yourImage.png"]];

Related

Remove status bar without making Navigation Bar shorter Objective-C

I'm making an app in which I have a navigation bar that contains a custom background image. It looks like this.
I want to remove the status bar (as it covers part of the Nav Bar image), however when I do it shortens the NavBar, like so:
I want to find a way to get rid of the status bar without shortening the nav bar and causing the image in the navBar to come all out of proportion.
Here is the code I use to set the background image of the NavBar.
[[UINavigationBar appearance] setBackgroundImage:[[UIImage imageNamed:#"navigationBar"] stretchableImageWithLeftCapWidth:0 topCapHeight:0] forBarMetrics:UIBarMetricsDefault];
Thanks!
Edit: Please note that I attempted to just change the height of the Navigation Bar, however the background image remained out of proportion.
UIImageView *logoImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"yourLogoImage"]];
[logoImageView setFrame:CGRectMake(0.0f, 0.0f, 200.0f, 44.0f)];
logiImageView.contentMode = UIViewContentModeCenter;
self.navigationItem.titleView = logoImageView ;
Will fix your UIImage stretching.
EDIT:
or
self.navigationController.navigationItem.titleView = logoImageView;

Can't set image in UINavigationBar to the center

I'm using two images in my navigaton controller. One for the rightBarButtonItem and one for the titleView. I created both in code. So my problem is that the title view is not in the center, it's a little bit closer to the left side. It's because the right bar button, it's sure, I tested it and found some related questions, but still couldn't solve the problem.
I tried [[UIBarButtonItem appearance] setTitlePositionAdjustment:UIOffsetMake(0.0f, 0.0f) forBarMetrics:UIBarMetricsDefault]; but doesn't helped me out. I would really appreciate any suggestions.
- (void)setupLogo {
[self setNeedsStatusBarAppearanceUpdate];
CGRect myImage = CGRectMake(0, 0, 41, 41);
UIImageView *myLogo = [[UIImageView alloc] initWithFrame:myImage];
[myLogo setImage:[UIImage imageNamed:#"logo.png"]];
myLogo.contentMode = UIViewContentModeScaleAspectFit;
self.navigationItem.titleView = myLogo;
[[UIBarButtonItem appearance] setTitlePositionAdjustment:UIOffsetMake(0.0f, 0.0f) forBarMetrics:UIBarMetricsDefault];
}
The titleView is centered between the left and right items. It's not centered on the nav bar.
One possible solution would be to add a dummy left bar button item of the same size as your right bar button item. This will force the titleView to the center.

Remove Top Bar area in iOS iPhone/iPad App

I'm trying to remove the blank Top Bar area (see screenshot), above the "Become a better you". There should be no margin between the text and the top edge, but at runtime it seems to insert that space there. We're not showing a title or navigation bar, and would like to remove this space. Any ideas?
Check that your top constraint connects with superview's top, not with top layout guide.
Frist You Try This Code UItabbar Remove One Pixel
[[UINavigationBar appearance]setShadowImage:[[UIImage alloc] init]];
Second One IS
UIImage *image = [UIImage imageNamed:#"top"];
[self.navigationController.navigationBar setBackgroundImage:image forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:image];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
[self.navigationController setNavigationBarHidden:FALSE];
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
and UIimageView also use tha same Image
Thanks for the suggestions guys. It turned out to be something else - the subview was centered, causing the gap at the top and bottom, because the subview was positioned based on bounds instead of frame.

UINavigationController background color changes that hide Back Button in iOS

Now I am trying to change UINavigationController background image with my custom Image.
I can change with following codes.
[navigation.navigationBar insertSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"navController.png"]] atIndex:1];
So I got following pic. That pic is right and show the BarButton.
But when I go to the detailViewController , there is no BackButton. However I can tap without seeing it.
After I back to MainViewController , my UINavigationController Background is happening like following pic.
They are hiding my button. I'm thinking atIndex:1 is making this problem because Index 1 is above 0 and All button Index must be 0.
That's why all buttons are disappearing.
So how can I solve that problem? Please help.
Thanks for your help.
// not supported on iOS4
UINavigationBar *navBar = [purchaseNavController navigationBar];
if ([navBar respondsToSelector:#selector(setBackgroundImage:forBarMetrics:)])
{
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"brnlthr_nav.jpg"] forBarMetrics:UIBarMetricsDefault];
}
Try using the appearance proxy provided by apple
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"your_image"] forBarMetrics:UIBarMetricsDefault];
that will set it for the entire application or you can use
[[self.navigationController.navigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"your_image"]];

transparent image in UINavigationBar

i have made a simple design in photoshop
when i tried to put it in Xcode i had some problems with NavigationBar
i used this code to change the UINavigationBar background image (a PNG transparent image):
UINavigationBar *navBar = [[self navigationController]navigationBar];
[navBar setBackgroundImage[UIImageimageNamed:#"navBar2.png"]forBarMetrics:UIBarMetricsDefault]
everything works fine but the problem is that the image appears in the navigationBar without transparency.
please someone help me to fix the transparency issue i search everywhere without any satisfied answer
NB! Im using IOS 5
You might try setting the navigation bar to translucent.
[navBar setTranslucent: YES];
Do you have it in your Storyboard? Try change the style of your navigation bar into black translucent.
What you can do is set the background color of the view of the navigationController the same as the backgrouond color of the main view.
//Set your view's background color
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"view_background"]]];
//Set your custom image for the navigationController
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed: #"navigation_bar_image"] forBarMetrics:UIBarMetricsDefault];
//And then set the background color of the navigationController the same as the one of the view
[self.navigationController.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"view_background"]]];
[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[self.navigationBar setShadowImage:[UIImage new]];
[self.navigationBar setTranslucent:YES];
And make sure you set up tint color to default.

Resources