Arrows at the bottom of the toolbar in iOS apps - ios5

Was wondering if anyone knew how to implement arrows in the bottom toolbar as shown below? Would be extremely grateful if someone could give me insight into this. I have seen a lot of apps with such arrows to navigate through pages and cannot seem to find them in XCode. See below...
THX :)

Just set a UIToolbar and attach it those two images (i'll give you the archive link with both images standard and retina): link
//Creating UIToolbar
toolBar = [[UIToolbar alloc]init];
toolBar.frame = CGRectMake(//set some frame);
toolBar.barStyle = UIBarStyleBlackOpaque;
[toolBar sizeToFit];
//Creating buttons
UIBarButtonItem *prev = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"previous.png"] style:UIBarButtonItemStylePlain target:self action:#selector(myaction:)] autorelease];
UIBarButtonItem *next = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"next.png"] style:UIBarButtonItemStylePlain target:self action:#selector(myaction:)] autorelease];
//Creating the array with the buttons
NSArray *items = [NSArray arrayWithObjects:prev,next, nil];
//Assigning the array to the toolbar
[toolBar setItems:items];
[self.view addSubview:toolBar];
[toolBar release];
You are done!

I'm guessing those arrows were custom made by Apple for Safari, Photo Library, etc.
I think you can make those in Paint if you don't have something along the lines of Photoshop.

Related

How can i add a next and previous button at the segmented Controller on a navigation bar in iphone application development?

I am in great trouble....How can i set next and previous button/arrow at my segmented bar...if anyone need brief about my problem then please see this link...How can i add a next and previous button at the segmented Controller?
i have attached an image to understand the problem...so anybody help me please....
NOTE THAT: In my current project it has more than 5 buttons to add at the segmented bar so when i will press next/previous arrow then segmented bar should be move from his place.If my question is not clear to you then please see my another link....
Thanks in Advance
EDIT:
UIBarButtonItem *previousBarButtonItem = [[UIBarButtonItem alloc] //init];
initWithTitle:#"<"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(previousBarButtonAction:)];
self.navigationItem.leftBarButtonItem = previousBarButtonItem;
[previousBarButtonItem release];
UIBarButtonItem *nextBarButtonItem = [[UIBarButtonItem alloc] //init];
initWithTitle:#">"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(nextBarButtonAction:)];
self.navigationItem.rightBarButtonItem = nextBarButtonItem;
[nextBarButtonItem release];
//This Portion For UIToolbar
topToolBar = [UIToolbar new];
topToolBar.barStyle = UIBarStyleDefault;
[topToolBar sizeToFit];
topToolBar.frame = CGRectMake(50, 410, 280, 50);
//Add buttons
UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:#selector(pressButton1:)];
UIBarButtonItem *systemItem2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self
action:#selector(pressButton2:)];
UIBarButtonItem *systemItem3 = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
target:self action:#selector(pressButton3:)];
//Use this to put space in between your toolbox buttons
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
//Add buttons to the array
NSArray *items = [NSArray arrayWithObjects: systemItem1, flexItem, systemItem2, flexItem, systemItem3, nil];
//release buttons
[systemItem1 release];
[systemItem2 release];
[systemItem3 release];
[flexItem release];
//add array of buttons to toolbar
[topToolBar setItems:items animated:NO];
self.navigationItem.titleView = topToolBar;
this is my current coding position now i have 4 buttons in the uitoolbar but only 3 button can see so i want to move this toolbar when i will press next or previous button to see the others button whose are out of frame of uitoolbar??
EDIT:
I able to scroll the navigation bar item using uiview animation but now my problem is when i press the next/prev button then it is moving from the current place according to the changing of the coordinate of the uitoolbar and moving over the pre/next baritem frame whose are not in the uitoolbar items. but it should be wothin a uiview and should change the coordinate within the uiview not out of the view...now tell me what can i do for this problem.
Firstly in figure the NavigationBar you are seeing is actually UIToolBar. Unfortunately it is not possible to add anymore controls on the UINavigationBar. But you can achieve exactly same UI with UIToolBar where you can add any controls.
So to achieve this use UIToolBar and not UINavigationBar. Also use UIBarButtonItem with custom title to achieve Next and Previous functionality.
EDIT
Here are few links for example of UIToolBar
http://www.codeproject.com/Articles/43658/How-to-Make-a-Toolbar-with-UIToolbar
http://osmorphis.blogspot.com/2009/05/multiple-buttons-on-navigation-bar.html
http://atastypixel.com/blog/making-uitoolbar-and-uinavigationbars-background-totally-transparent/
But this all explains using codes. Instead using Interface Builder, it becomes too easy to use UIToolBar (if coding is not so important).
I think this is being slightly overcomplicated- can you not just set the text of the two UIBarButtonItems to "<" and ">"?

UIToolbar Resizing causes weird UIBarButtonItem size in Landscape

When I create and add a UIToolBar and UIBarButton items, how can I get the toolbar and items to appear properly in both orientations. This is what I have so far:
self.toolbar = [[[UIToolbar alloc]initWithFrame:CGRectMake(0, 372, 320, 44)]autorelease];
self.toolbar.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.deleteButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:#selector(deleteButtonClicked)] autorelease];
self.deleteButton.style = UIBarButtonItemStylePlain;
UIBarButtonItem *flexibleSpace = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease];
self.shareButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:#selector(shareButtonClicked)] autorelease];
self.shareButton.style = UIBarButtonItemStylePlain;
self.navigationItem.leftBarButtonItem = backItem;
NSArray *toolbarItems = [NSArray arrayWithObjects:self.shareButton,flexibleSpace,self.deleteButton,nil];
[self.toolbar setItems:toolbarItems animated:NO];
As you can see from the images, the UIBarButtonItems look correct in portrait, but weirdly squished and off center (especially the trash icon), in landscape. Is there an obvious solution I'm missing, or do I have to do manual resizing to get this right?
It's a subtle difference, but here's what it should look like:
You have to look at the Autoresizing option in the Size inspector both for the UIToolBar and the buttons. UIToolBar might also have a checkmark set for Autoresize subviews uncheck that so it does not influence your buttons.
The answer, at least until iOS 5 is to use the UINavigationController's built in toolbar instead of creating your own. The built in toolbar will resize correctly and automatically.

UIToolbar with dynamic number of barButtonItems and multiselection

I want to create a UIToolbar that will add it´s buttons from an array. Or perhaps a segmented control.
The problem is that i don´t know before hand how many buttons or segments I need and also if its more than, say 4-5 buttons I want to be able to scroll or similar horizontally for display more buttons.
I want to be able to have multi selection so which approach would be the best to take for this?
A tableViews content will be based on the selection of the buttons on the toolbar.
Any tips for how I can make this work? or a recommendation for a tutorial out there regarding this would be much welcomed.
Thanks in advance!
UIBarButtonItem *btnAdd = [[[UIBarButtonItem alloc] initWithTitle:#"Add"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(AddOperation)] autorelease];
UIBarButtonItem *btnEdit = [[[UIBarButtonItem alloc] initWithTitle:#"Edit"
style:UIBarButtonItemStyleBordered
target:self
sction:#selector(EditOperation)] autorelease];
UIToolbar *rightToolBar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 100, 46)] autorelease];
rightToolBar.backgroundColor = [UIColor clearColor];
rightToolBar.tintColor = [UIColor colorWithRed:40.0/255.0 green:48.0/255.0 blue:51.0/255.0 alpha:0.0];
NSArray *buttonsRight = [NSArray arrayWithObjects:btnEdit, btnAdd, nil];
[rightToolBar setItems:buttonsRight];
[self.view addSubView:rightToolBar];

How can I fix this NavigationController and UIToolbar offset issue in Objective-C?

I'm adding a couple of buttons to an already-existing NavigationController. The two buttons are added to a UIView, which is pushed onto the NavigationItem. The buttons stop and reload a UIWebView.
Problem is that there's a slight offset issue that is making it all look pretty ugly. I wish I could set the UIToolbar to transparent or clear background but that doesn't seem to be an option. Can't seem to use negative offsets either. I've got color matching, but if you look closely there's 1px or 2px of highlighting up top that's causing a visual mismatch and then a slight offset at the bottom.
Some relevant code below (based on this, inbound Googlers). What are my options to resolve this?
// create a toolbar for the buttons
UIToolbar* toolbar = [[UIToolbar alloc]
initWithFrame:CGRectMake(0, 0, 100, 45)];
[toolbar setBarStyle: UIBarStyleDefault];
UIColor *colorForBar = [[UIColor alloc] initWithRed:.72 green:0 blue:0 alpha:0];
toolbar.tintColor = colorForBar;
[colorForBar release];
//[toolbar setTranslucent:YES];
// create an array for the buttons
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];
// create a standard reload button
UIBarButtonItem *reloadButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self
action:#selector(reload)];
reloadButton.style = UIBarButtonItemStyleBordered;
[buttons addObject:reloadButton];
[reloadButton release];
// create a spacer between the buttons
UIBarButtonItem *spacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil
action:nil];
[buttons addObject:spacer];
[spacer release];
// create a standard delete button with the trash icon
UIBarButtonItem *stopButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemStop
target:self
action:#selector(stopLoading)];
stopButton.style = UIBarButtonItemStyleBordered;
[buttons addObject:stopButton];
[stopButton release];
// put the buttons in the toolbar and release them
[toolbar setItems:buttons animated:NO];
[buttons release];
// place the toolbar into the navigation bar
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithCustomView:toolbar];
[toolbar release];
Update: Alignment was fixed by suggestion by #Jacob below. Now, how to solve the highlighting mismatch?
I've had this same exact issue before, and after some hacking around, I figured this out:
You need to set the height of the UIToolbar's frame to 44.01 for this to work.
EDIT: Re: highlighting mismatch -> You can try setting the backgroundColor to the colorForBar.
UIToolbar* toolbar = [[UIToolbar alloc]
initWithFrame:CGRectMake(0, 0, 100, 44.01)];
UIColor *colorForBar = [[UIColor alloc] initWithRed:.72 green:0 blue:0 alpha:0];
toolbar.tintColor = colorForBar;
toolbar.backgroundColor = colorForBar;
Instead of putting the buttons into a toolbar, you might just make them children views of a parent UIView. You can position a button directly through its frame or center property, without use of spacers, etc.

iPhone: adding segmented control to toolbar instead of buttons within navigation controller?

im new to iphone programming so if you could help me out I would appreciate it- i have been all over the web and cant find the answer to this.
my current setup is like this
navigation controller in MainWindow.xib > View in navigation controller in MainWindow.xib calls RootViewController.xib > RootViewController.xib contains a single tableview.
i can then load in a toolbar using the following code in RootViewController.m
UIBarButtonItem *buttonOne = [[UIBarButtonItem alloc] initWithTitle:#"One"
style:UIBarButtonItemStyleBordered target:self action:#selector(buttonOnePushed)];
UIBarButtonItem *buttonTwo = [[UIBarButtonItem alloc] initWithTitle:#"Two"
style:UIBarButtonItemStyleBordered target:self action:#selector(buttonTwoPushed)];
NSArray *barArray = [NSArray arrayWithObjects: buttonOne, buttonTwo, nil];
[buttonOne release];
[buttonTwo release];
[self setToolbarItems:barArray animated:YES];
[self.navigationController setToolbarHidden:NO animated:YES];
this code works for buttons. but i cannot for the life of me find out how to add a segmented control instead of the buttons. i have tried an array with two segmented controls in it, but then can't add the array to the toolbar.
if anyone could let me know some code that will add segmented controls in the same fashion as i have used to add the buttons i would greatly appreciate it.
thanks, dave.
The solution to this is to (1) create the UISegmentedControl with all its buttons, etc., and then (2) create a UIBarButtonItem using the initWithCustomView:(UIView *)view initializer and provide the segmented control as the variable to this. Then add the Bar Button Item to the Toolbar using an array just like you did in your example code.
Make sure you set a target and action for your segmented controller, and I recommend setting its style to UISegmentedControlStyleBar. It'll look just like the one at the bottom of the Maps app. Hope this was what you are looking for.
Here is my code which adds a segmented control to the toolbar of a navigation controller.
:
NSArray *segItemsArray = [NSArray arrayWithObjects: #"Settings", #"Templates", #"Notes", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:segItemsArray];
segmentedControl.frame = CGRectMake(0, 0, 200, 30);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.selectedSegmentIndex = 2;
UIBarButtonItem *segmentedControlButtonItem = [[UIBarButtonItem alloc] initWithCustomView:(UIView *)segmentedControl];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
NSArray *barArray = [NSArray arrayWithObjects: flexibleSpace, segmentedControlButtonItem, flexibleSpace, nil];
[self setToolbarItems:barArray];