How to add image in place of text in navigation bar? - iphone

How to add image in place of text in navigation bar ?

Can you use the titleView property of the UINavigationItem ?

UINavigationBar is a subclass of UIView. Thus, you can create your UIImageView object and add it as a subview in your UINavigation bar.
[navigationBar addSubview:imageView];
One thing you need to keep in mind that the navigationbar dimensions which is 320X44 in Portrait & 480X20 points in landscape for iPhone.

u can create an image view with some image and add it to the title view of navigation bar
like:--
self.navigationItem.titleView = myImageView;

Related

Centering vertically in the viewcontroller with navigationbar in swift?

I tried to center an UIImageView in my UIViewController which has a navigation bar at the top and what I wanna do is to have my UIImageView centered between the bottom of the navigationbar and the bottom of the view (with constraints of course). But Xcode make it vertically centered in the view from top of the view (centered between top of the navigationbar and bottom of the UIViewcontroller).
Is there a way to do what I wanna do? with constraints.
Add another UIView (empty) with constraints with top and bottom layout guide. Then add your UIImageView as a subview and align vertically and horizontally.
Try calling self.edgesForExtendedLayout = [] inside viewDidLoad()
Assuming your UIViewController in embedded in a UINavigationController then you should be able to make the center of your UIImageView equal to the center of the UIViewController's view. Otherwise if you added the nav bar manually you will need to offset the center Y coordinate of the UIImageView by the height of the nav bar.

UITabBarController hides but white space remaining

I have UITabBarController in my app.
In a particular view I want to hide the tabbar and display the content up to the below line.
For that I used the code in the view
-(void)viewWillappear{
[self.tabBarController.tabBar setHidden:YES];
}
It depends what your content is, but if it's inside a container, like a UIView, you can change the autoResizingMask to be
myView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
and it should do the right thing.

Is possible to add an UIImageView to an UINavigationBar title?

I have an UINavigationBar, and I'm trying to add the user avatar to before the text, and I want 't so it's just before, and thought if I add it with IB, if the tabBar title is longer it would look ugly, so how could I add it on the front of the navBar? It would look like this of Osfoora:
You could add UIImageView in the titleView property of UINavigationBar.
myImageView is type of UIImageView.
self.navigationItem.titleView = myImageView;
add it as a barbutton image if you are not using any barbutton.

Is it possible to set image or button at the center of navigationbar in iphone?

Is it possible to set image or button at the center of navigationbar in iphone?
Yes, have a look at the UINavigationItem's titleView property. In my application I added a UIView with a UILabel and UIImageView, for instance.

Navigation Controller Transparent Bar Style is not working

I am using a navigation controller, and I have the style set to :
navController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
But when I run my program, the navigation controller looks like it is on top of a white background, not my background. When I push a controller, left or right, all my view, the current one, shifts to the top exactly the size of the navigation bar. And it is there where I can see my background through the navigation controller bar. Any ideas? When my barStyle is set to opaque, everything looks fine. I was thinking on setting my view frame a negative 'y' value, but I think there should a more elegant way.
I believe the UINavigationController assumes that your controller view frames don't include the area beneath the navigation bar.
UIBarStyleBlackTranslucent is more often used for UIToolbar, so Apple probably didn't make it easy to use it nicely with UINavigationBar. You'll probably need to abandon the UINavigationController, or start hacking the frames (careful with rotations), if you want to reliably render under the bar area.
Also, if your intention is to hide the navigation bar after a few seconds, you'll have a much easier time if you make it fade out (like the Photos app) instead of trying to slide it up (like Mobile Safari). Trust me on that one... that took me a lot of time to learn the hard way.
Simply use a transparent background image, and translucent = YES to allow the content to flow below the bar. Works on iOS 5 / 6. Add in viewDidLoad.
self.navigationController.navigationBar.translucent = YES;
UIImage * backgroundImage = [UIImage imageNamed:#"spacer.gif"];
[self.navigationController.navigationBar setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:UIBarMetricsDefault];
I attached the spacer.gif image here, a single 1px x 1px transparent image.
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.169 green:0.373 blue:0.192 alpha:0.9];
self.navigationController.navigationBar.translucent = YES;
Note:
Don't use self.navigationBarStyle and self.navigationBarTintColor to change.
Add the last two statements to your viewDidLoad.
I ran into this same problem (in 3.1.3) and while you can't set the bar style after the navigationBar has already been setup you CAN set the tintColor and translucent values whenever you like:
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
self.navigationController.navigationBar.translucent = YES;
Will create the 'blackTranslucent' bar, I change the navigationBar look when I push certain view controllers onto the stack.
I had the same problem, and I solved it by making the background of the root view the same as my view. The white area behind the navigation bar turned out to be the root view.
The navigation controller offsets the coordinate sytem of all it's subviews so they draw below the navigation bar.
Extend your view's frame into the negative y domain for it to draw under the navigation bar.
You need to set the barstyle in your info.plist file for it offset everything correctly.
However, I haven't tried it since the 2.1 f/w was released, but when I tried this in 2.0 I found that the setting was lost after a rotation from portrait to landscape.
try to use this, may be it will helpful.
_topToolBar.barStyle = UIBarStyleBlackTranslucent;
_topToolBar.alpha = 0.3;
I had a same problem.I solved!
ImageViewExtendController *detailImageController = [[ImageViewExtendController alloc] init];
[detailImageController loadImage:url];
[self.navigationController pushViewController:detailImageController animated:YES];
If you set your nav controller's navigationBar to transparent in your App delegate early enough (It worked for me before adding the nav controller to the window), it will automatically shift your view up underneath the navigation bar.
Unfortunately it does not also shift your view underneath the status bar. Sad, it looks like you need to implement your own version of UINavigationController. Luckily, it's not too bad as UINavigationBar is pretty reusable.
Try this:
self.tabBarController.tabBar.superview.backgroundColor = [UIColor blackColor];
Change the Extend Edges options in child viewControllers
As for example, in xcode editor, go to your first viewcontroller child and unset the options:
Extend Edges;
Under Top Bars;
Under Bottom Bars;
Under Opaque Bars;
This way your child ViewController will not layout starting below the status bar of the navigation controller, neither the tabbar or the toolbars
hope it may help anyone