Navigation Bar or ToolBar trouble in xcode - objective-c

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.

Related

UIBarButton Not does not appear on navigation bar - iOS

I am adding two UIBarButtons in my navigation bar. Surprisingly, left button works perfectly and appears on left side. But by using same method, right button does not appear. It appears while view is loading but then disappears.
Here is the code I am using:
SWRevealViewController *revealController = [self revealViewController];
[self.navigationController.navigationBar addGestureRecognizer:revealController.panGestureRecognizer];
UIBarButtonItem *revealButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"reveal-icon.png"]
style:UIBarButtonItemStyleBordered target:revealController action:#selector(revealToggle:)];
self.navigationItem.leftBarButtonItem = revealButtonItem;
[self.navigationItem.leftBarButtonItem setTintColor:[UIColor whiteColor]];
UIBarButtonItem *rightRevealButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"cashcoin.png"]
style:UIBarButtonItemStyleBordered target:revealController action:#selector(rightRevealToggle:)];
self.navigationItem.rightBarButtonItem = rightRevealButtonItem;
[self.navigationItem.rightBarButtonItem setTintColor:[UIColor whiteColor]];
I am using SWRevealViewController for gesture recognition.
Check your code again, You should set your bar items in viewDidLoad
You might be setting rightBarItem to nil in viewWillAppear or viewDidAppear as you mentioned that button appears and then disappear on screen loading.
Swap buttons i.e left item to right and vice versa.
I hope your issue will be resolved.

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…

UISearchBar embedded in UIBarButtonItems (Only available in iPad documents)?

I'm trying to insert an UISearchBar to my Toolbar of my TableView but it fail to built my app (iOS5.1) with this error
UISearchBar embedded in UIBarButtonItems (Only available in iPad documents)
http://img.muse-gaming.org/file/1359259573-uisearchbar.png
And i really can't figure it out...
Any idea ?
That being said, it might be possible to make your own view that looks and works like a UIToolbar that does allow a UISearchBar.
Solution is that Use a navigation bar instead of a toolbar. Set the search bar to the navigation bar's title view.
Or Yu can add it Programmatically
self.searchBar.frame = CGRectMake(70, 3, 230, 44);
UIToolbar * searchToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0,0+20,[self view].bounds.size.width,52)];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *infoButtonItem=[[UIBarButtonItem alloc]initWithTitle:#"Update" style:UIBarButtonItemStyleBordered target:self action:#selector(infoButtonClicked)];
UIBarButtonItem * searchBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.searchBar];
[searchToolbar setItems:[NSArray arrayWithObjects:flexibleSpace,infoButtonItem,searchBarButtonItem, nil] animated:YES];
[self.view addSubview:searchToolbar];
Apple fixed this in Xcode 8.2. I think they disabled it before because popovers were not allowed on iOS before iOS 8.0 and a search bar in a toolbar implies that a popover will be used most times.

Change UIBarButtonItem into Simple Icon

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];

setRightBarButtonItems iOS5 not working

I am using the new API for UINavigationItem setRightBarButtonItems like this:
UIBarButtonItem *buttonSettings = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"settings.png"]
style:UIBarButtonItemStylePlain
target:self
action:#selector(showSettings:)];
UIBarButtonItem *buttonLogout = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPageCurl target:self action:#selector(showSettings:)];
[[self navigationItem] setRightBarButtonItems:[NSArray arrayWithObjects:buttonLogout, buttonSettings, nil]];
But, only 1 button (settings) is appearing and logout button is not appearing at all. What am I doing wrong?
Thanks
You are not allowed to do it:
UIBarButtonSystemItemPageCurl
The system page curl button.
This bar button image can be used only for bar button items placed on toolbars.
Available in iOS 4.0 and later.
Declared in UIBarButtonItem.h.