Hi
i'm displaying UIBarButton on Navigation bar as back button,how can i've the default back button style for the UIButton.
Regards
Sam.
In the parent view controller when pushing the view in didselectrowInIndex method just use the following cod:
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStyleBordered target:self action:nil];
[self.navigationItem.backBarButtonItem release];
three20 includes a custom style for back-like buttons
You can use custom button with navigation button image.
Creating a left-arrow button (like UINavigationBar's "back" style) on a UIToolbar
What you are looking for can be done by making a custom UIButton
Related
I have a done button on navigation bar, I want to have it shown as blue. But just doing the following seems doesn't help. What am I missing here? I know that if the navigation bar is in black color, the button will be shown as blue automatically, but I don't want the color of the navigation bar on this view controller to be black.
- (UIBarButtonItem *)doneButton {
UIBarButtonItem *doneButton = [[[UIBarButtonItem alloc] initWithTitle:#"Done"
style:UIBarButtonItemStyleDone
target:self
action:#selector(done:)] autorelease];
return doneButton;
}
Changing combination of NavigationBar and BarItems appearance is not easy tasks before iOS5.
Standard way is to subclass NavigationBar. This nice sample code may help, even if not directly.
In iOS5, you can use "appearance proxy". Nice tutorial is here
You don't need to define your own done button. As long as it's called 'done' you can use the predefined barbuttonsystemitemdone:
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone Target:...
When creating a new nav-based iphone app, how do you add a button to the nav bar?
I've tried editing the rootviewcontroller.xib and adding a nav bar and nav item and bar button item, but it doesn't seem to make any difference.
Is there a simple way of achieving this through IB, or do i have to duck into code somewhere?
Thanks
Unfortunately this requires a little bit of code. Create your UIBarButtonItem in interface builder and hook it up to an IBOutlet in your view controller. Then, in viewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
// Assuming "myButton" is the UIBarButtonItem.
self.navigationItem.leftBarButtonItem = myButton;
}
Assigning to rightBarButtonItem works similarly. See the UINavigationItem Class Reference for more information.
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStyleBordered target:nil action:nil];
I would like to center a button in my navigationBar, which is currently defined as a rightBarButtonItem :
UIBarButtonItem *audioBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:#selector(toggleAudioPlayback:)];
self.navigationItem.rightBarButtonItem = audioBtn;
[audioBtn release];
You can use the .titleView property of your navigation item - but you'll need to create your own assets for this (you won't be able to use a UIBarButtonItem). From Apple's docs:
...(titleViews) can contain buttons. Use
the buttonWithType: method in UIButton
class to add buttons to your custom
view in the style of the navigation
bar. Custom title views are centered
on the navigation bar and may be
resized to fit.
I created a custom navigation bar and a right navigation button using the XIB. This works fine. But I need to to customize the tint color of the right navigation button. At the moment this tint color is the same color as tint color of navigation bar. I need a different color for this right button. Is there any way to change this color?
Thank you.
In iOS 5 there is 'appearance' feature:
[[UIBarButtonItem appearance] setTintColor:YOUR_COLOR];
Not to my knowledge, the button inherits the tint color of the navigationBar. What you can do is set a customView for the navigationItem:
This is how you set it with one of the SDK's buttons:
UIBarButtonItem *shareButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:#selector(shareButtonHandler:)];
[self.navigationItem setRightBarButtonItem:shareButton];
[shareButton release];
Instead you can do it like this:
UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"yourImage.png" style:UIBarButtonItemStyleBordered target:self action:#selector(customButtonHandler:)]];
To use an image you made in photoshop etc.
There is als an initWithCustomView:UIView or initWithTitle:NSString you can use.
Sorry no "one-line solution" :)
Swift 3.x
UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName : Color.primaryActionColor], for: .normal)
If you have navigation bar button item with custom view you should convert to UIButton first:
navigationItem.rightBarButtonItem?.customView as? UIButton
Then you can add the attributes of UIButton such as:
button.setTitleColor(UIColor.black.withAlphaComponent(0.1), for: .normal)
i have a problem while adding button to the navigation bar.. My application consist of two view controllers added to the viewControllers array of a tabBarController. Inturn this tabBarController is added to the viewControllers array of a navigationController. In one of the views i have a textfield for entering dates . On the tap of this textfield the datepicker will pop up. simultaneously i want to display a done button on the navigation bar. how can i do this... i tried using
self.tabBarController.navigationController.navigationItem.rightBarButtonItem = self.doneButton;
But this is not working...
Pls help me out..
Try this code,
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#"Done", #"")
style:UIBarButtonItemStyleBordered
target:self
action:#selector(DoneButton)] autorelease];
self.navigationItem.rightBarButtonItem = addButton;
Best of luck.
Try with this
UIBarButtonItem* _doneButton;
self.navigationItem.rightBarButtonItem = _doneButton;
use this one:
UIButton *myBtn = [[UIButton alloc]init];
[self.navigationItem.titleView addSubview:myBtn];