Change UIBarButtonItem into Simple Icon - objective-c

I am trying to display the "settings gear" instead of the word "Settings" in by navigation bar. Does anyone know how to do this? Thank you!
UIBarButtonItem *btnGo = [[UIBarButtonItem alloc] initWithTitle:#"Settings"
style:UIBarButtonItemStyleBordered target:self action:#selector(settingsAction)];
self.navigationItem.rightBarButtonItem = btnGo;

Unfortunately, there is no default way to get this image. You should use initWithImage:style:target:action:
and add an image of your own. You can make one yourself, or get pre-rolled from some where like Glyphish: http://www.glyphish.com

you can try making a UIButton first , setting the gear image on it and than
UIBarButtonItem *btnGo = [[UIBarButtonItem alloc] initWithCustomView:btn];

Related

how to change the UIBarButtonItem button design?

I am newbie for iPhone application.
What I have is as below.
UIBarButtonItem *flipButton = [[UIBarButtonItem alloc]
initWithTitle:#"Flip"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(flipView)];
self.navigationItem.leftBarButtonItem = flipButton;
[flipButton release];
BUT, problem is button design. It is just square button.
How can I make this button to same as Back button?
Any idea/ suggestion would be appreciated.
I was trying with
self.navigationItem.leftBarButtonItem.title = #"Back";
self.navigationController.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(goBackToSAMA:)] autorelease];
but its working working. Not working means, goBackToSAMA is not getting invoked and button text is also not coming to Back.
One possiblity might be to change the back bar button via this method:
backButtonBackgroundImageForState: barMetrics:
Another possibility might be to replace the "backBarButtonItem" with a custom view.
If you want to roll your own custom bar button item, the option you're looking for is the "UIBarButtonItem" method "initWithCustomView", and that's where you can put in designs of your choosing.
As far as I know, ther is only one way how to display the standard back button. You have to push UINavigationItem in UINavigationBar. Or better: there need to be navigation item to be popped.
IMPORTANT: This will not work nice with UINavigationController's bar, so use your own!
UINavigationItem *firstItem = [[UINavigationItem alloc] initWithTitle:#"Go Back"];
UINavigationItem *secondItem = [[UINavigationItem alloc] initWithTitle:#"Something"];
navigationBar.items = #[ firstItem, secondItem ];
This code will display “Something” as a title and to the left, there will be back button saying “Go Back”. By default it shows the title of previous item, but you can customize it:
firstItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Another Title"
style:UIBarButtonItemStyleBordered
target:nil
selector:nil];
Note that the target and selector are nil. You can not customize the action of back button like this, because it is special. You will need to implement protocol UINavigationBarDelegate and this method:
– (BOOL)navigationBar:(UINavigationBar *)bar shouldPopItem:(UINavigationItem *)item {
[self doYourActionHere];
return NO; // Returning YES, would trigger pop animation.
}
Or just use custom background image…

Navigation Bar or ToolBar trouble in xcode

Ok I was looking at the iPhone iCal app, and was curious whether that top bar is a navigation bar or a toolbar? ive tried using both, but also i cannot figure out how to change the size of the buttons to be as small as the + button in the top right... very confused.. I'm assuming its a navigation bar, but when i read the description of the navigation bar, it said that whenever you are to add a button or item onto the bar, you cannot connect it directly... no idea how else to do it... but anyone wanna help with this issue?
If you are mentioning about this one
It is not UITabBar , it is UINavigationBar, the button on extreme left is inbuilt backbutton of UINavigationBar and the that at right is an extra button that you can add , its clearly shown in this question , and to change the type (ie, + button) you can simply change the button style using
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:#"Done"
style:UIBarButtonSystemItemAdd target:nil action:nil];
adding button to UINavigationBar
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:#"Done"
style:UIBarButtonSystemItemAdd target:nil action:nil];
rightButton.width=10;
rightButton.height=10;
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:#"Title"];
item.rightBarButtonItem = rightButton;
item.hidesBackButton = YES;
[bar pushNavigationItem:item animated:NO];
[rightButton release];
[item release];
But normally you would have a navigation controller, enabling you to write:
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:#"Done"
style:UIBarButtonSystemItemAdd target:nil action:nil];
self.navigationItem.rightBarButtonItem = rightButton;
[rightButton release];
Hope this helps,
regards
The top bar with RED circle is UINavigationaBar & the bar with GREEN circle is custom designed.
You can the use the below written code to add the system defined Add button to UINavigationaBar
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:#"Done"
style:UIBarButtonSystemItemAdd target:nil action:nil];
I realized that in fact you do not need code to get the button to shrink to the size of the + button in the top right corner of the calendar app. In fact, once you are in the storyboard. Open up the utilities tab on the right. Then open the attributes inspector. and where it says Identifier, the drop down tab has options. Choose the add option.

How to add round information button as a rightbarbuttonitem to navigation controller?

I have a navigation controller. I want to add a right bar button item to that navigation controller. I am able to add one, but I want a specific style: labeled 'i' and also round in shape. Is there any property to do that?
I think there is no property what you asked. But you can make a custom image and use this method.
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithImage:customImage style:UIBarButtonItemStylePlain target:self action:#selector(customButton:)];
addButton.enabled = YES;
self.navigationItem.rightBarButtonItem = addButton;
For more details you can refer UIBarButtonItem ClassReference.

Add a UIBarButtonItem next to UINavigation Back button

I want to add/show a button/custom view next to default back button. So it would look like this
< BACK | HOME
I want to preserve the default look and feel of back button.
Thanks in advance.
UIBarButtonItem *home = [[UIBarButtonItem alloc]initWithTitle:#"Home" style:UIBarButtonItemStyleBordered target:self action:#selector(HomePressed:)];
self.navigationItem.leftItemsSupplementBackButton = YES;
self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:home, nil];
this code works for me, the back buttom UI didn't change. you would need to implement HomePressed:
You should set the leftBarButtonItems array on your view controller's UINavigationItem.
self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects....];
See http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationItem_Class/Reference/UINavigationItem.html for more information.

How to make UIBarButtonSystemItem bordered?

I have play UIBarButtonItem on UIToolbar. I want to make the style bordered. As it is system item, is there a way to make it bordered style?
UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:#selector(play:)];
Set the UIBarButtonItem's style property:
systemItem1.style = UIBarButtonItemStyleBordered;
See the UIBarButtonItem class reference.