Position a bar button item in a toolbar - iphone

I have a tool bar at the top and bottom of my application and I need to create buttons to put into the toolbars. The ones designing this application would like space placed between the buttons on the toolbar. Aside from manually coding in a position change for the buttons, is there a better way to accomplish this through Interface Builder?

You can add a bar button of type UIBarButtonSystemItemFlexibaleSpace in the place where you want the space.
UIBarButtonItem *barButton1 = ...
UIBarButtonItem *barButton2 = ...
UIBarButtonItem *flexibleSpaceBarButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
toolbar.items = [NSArray arrayWithObjects:barButton1,
flexibleSpaceBarButton,
barButton2, nil];

As EmptyStack wrote, you can use the UIBarButtonItemFlexibleSpace to create spaces between buttons. You can either use the code written above or do it in the Interface Builder. In IB you will have to place the toolbar and then you can find toolbar items if I remember correcly around the end of the items list. So you can add a flexible space item to the toolbar, play around with its width and then add a 'real' bar button to the toolbar. You can declare outlets and assign actions to the barbuttons just like for normal UIButtons.

Related

UINavigationController toolbar buttons not animating when pressed

I have few UIViewControllers embeded in NavigationController, everything is cool when it comes to change screen titles, button titles, hiding/showing navigation bar (top bar) or toolbar (bottom bar), but - I cannot force toolbar buttons to have this animated shadow when pressed, as navigation bar buttons have. What's more, toolbar buttons are as black as toolbar - shouldn't button be slightly lighter color than toolbar?
I hope it's clear, because I couldn't find it nor even come up with reasonable title
If you want a black bar (navigation or toolbar), set its barStyle to UIBarStyleBlack in addition to or instead of tinting it black. This lets it know that the buttons should be tinted differently than if the bar was any other color.
I am not able to understand you whole problem but for the toolbar problem you can give those buttons different colors and also can give an effect of changing color of button which is clicked
UIBarButtonItem *toolBtn = [[UIBarButtonItem alloc] initWithTitle:#"Share and Upload"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(your_Target)];
toolBtn.tintColor = [UIColor redColor];
Now suppose toolBtn is your first button in toolbar and on click of it you want to change its color then in your target function
-(void)your_Target{
UIBarButtonItem *button1 = [[your_Toolbar items] objectAtIndex:0];
button1.tintColor = [UIColor brownColor];
// or you can simply loop all toolbar buttons and change the color of only clicked one and for rest keep it default
}
Hope this will help you.. and sorry for my bad english :)

iPhone - How to customize the UINavigationBar back button with my texture background

I am able to customize the back button on my navigation bar, but in order for me to show the left arrow shape, do I need to create my customized image with the left arrow specifically?
Or there is a way to use the original back button with the arrow shape, while just apply my background image onto it?
Thanks in advance!
Set yourButton the customized image with the left arrow
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:yourButton] autorelease];
You cannot modify the original BACK button.

What is the name of the View that shows options like the Camera Roll?

I want to create a button that show options like the Send option of the Camera Roll, but I don't know what kind of view is this to add the button, can anybody help me?
I think you are looking for an UIBarButtonItem created with UIBarButtonSystemItemAction.
UIBarButtonItem * baritem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction systemItem target: some_view action:#selector(some_method:)];
Reference - scroll to near bottom to see constants for possible predefined buttons with examples.

How to do iPhone's SMS app SPECIAL viewController shifting?

If anyone has used the iPhone's SMS app, there is a special animation with the compose view.
When you first press compose, a modal view controlelr is shown. However as soon as you press send, it shifts to your chat view controler. But here are a few weird behavior:
1) The keybaord stays intact. Usually when you pop and push new controllers, you lose your keyboard positions.
2) Further evidence that there was no pop/pushing of new controllers because the actual view did not change. As soon as you press send, the message "slides" up to the bubble view.
3) However, if there really IS no popping/pushing of controllers, how do you change the buttons on the navigationbar? The top left button also changed from the square "cancel" button to a arrow-like back button.
Any ideas how to implement this experience?
You can change the characteristics of the navigation bar in a view controller. You can also change the appearance of the screen by altering the viewController.view directly. In this example, when the user presses send you could use the following code to alter the nav bar:
UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithTitle:[NSString stringWithFormat:#"Messages:(%i)", messageCount] style:UIBarButtonStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = back;
[back release];
UIBarButtonItem *edit = [[UIBarButtonItem alloc] initWithTitle:#"Edit" style:plain target:self action:#selector(editMessage)];
self.navigationItem.rightBarButtonItem = edit;
[edit release]
And then you implement editMessage:
- (void)editMessage {
//Go into edit mode, whatever that code looks like.
}
They then simply fail to call [self.textField resignFirstResponder] after you hit send, so the keyboard stays up there. You will notice that if you load an old conversation the view loads with the send box on the bottom of the screen and no keyboard. This is in keeping with the standard behavior of UITextField objects.
Hacking the view directly is explained in the help files for UIView, and can be kind of a pain. I'm honestly not sure how they draw that pretty IM interface, I'll leave that up to another expert.
I've actually implemented a very similar UI for one of my apps. This is how did it:
The main control is a UITableView. The two buttons at the top "call" and "add to contacts" are the table view header view.
Each cell is drawn from 8 different images.
- One for each corner.
- one that stretch and fills the gap between the top left and top right corners.
- One that stretch and fills the gap between the top left and bottom left corners.
- One that stretch and fills the gap between the top right and bottom rightt corners.
- One that stretch and fills the gap between the middle left and the middle right.
- One that stretch and fills the gap between the bottom left and bottom right corners.

Creating buttons for a Navigation bar

I have a button as the right button on my navigation bar:
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:#"Add" style:UIBarButtonItemStyleBordered target:self action:#selector(addToFavouritesButtonPressed:)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
All good, except I'd like it to be an image of a star with a little plus on it. Thought it would be easy to just create a png and set the UIBarButtonItem's image property. Which it is, however 2 things. It puts the gloss and bevel at the left and right side of my image, but not on the image itself and secondly I can't find a recommended size of button in the docs.
Is there an easy way of creating a button image and the system to format it so it looks like it is part of the Navigation Bar? If I attempt to create the gloss and bevel in Photoshop it looks good but doesn't look quite like the system generated buttons on the left side.
Hope that makes sense and any pointers would be appreciated,
Dave
Doh, didn't have an alpha channel in my png, created a mask and all looks good.