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.
Related
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;
I am trying to customise the navigation bar with title view.
But it seems setting title view comes with its own left and right and top paddings.I was expecting the title view to cover the whole navigation bar according to the frames given.
Is it expected behaviour and if YES than how to deal with that?
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 375, 44)];
view.backgroundColor = [UIColor greenColor];
//Navigation Bar
self.navigationItem.titleView = view;
If you just want the navigation bar to be green use [self.navigationController.navigationBar setBarTintColor:[UIColor greenColor]]; in iOS 7+ or [self.navigationController.navigationBar setTintColor:[UIColor greenColor]]; in iOS 6-
Yes, it seems it is not possible to remove that left/right padding. This is the screenshot form debugging views in Xcode after running your code
The outside view that is gray is the navigationBar and the green is obviously the titleView. No matter the frame for the titleView, it is clipped.
Apple documentation says just this:
Custom title views are centered on the navigation bar and may be resized to fit.
I think the only solution would be to subclass the navigationBar, so that you override the titleView frame.
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.
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"]];
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.