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

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.

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 :)

UIBarButtonItem greyed out

I am adding two UIBarButtonItems to a UINavigationBar. The first of these is a system item - the search button - and works great. The second is a custom image (a small white Glyphish icon), but when I add this the image becomes grey. The button is perfectly clickable, just grey. Does anyone have an idea why this might be happening?
I do believe the alpha levels are correct. If I put the same icon in a UIBarButtonItem on a UIToolbar (rather than a UINavigationBar) this is how it appears:
Then, try cleaning the target.
Shift + cmd + K
It looks like it is in a highlighted state? If you're creating this button programmatically you might want to check if its UIControlState == UIControlStateHighlighted
You are using a toolbar type icon image. That Glyphish icons on toolbars and TabBars only use alpha layers. But if you are building a button you have to use a standard image. Open the image in any image editor and use the colors you want for your button and the transparent values for alpha layer where you want. It is, in some way, the inverse to the images made of alpha layers in tabbars.
I had been using a grey icon earlier. When I realized it was the wrong color, I suffixed the file with "-grey" and brought in a white icon, which took over the name of the grey icon. But somehow Xcode was still retrieving the old icon, despite its name being changed in the project (and thus in the Finder). Cached maybe? It's a mystery to me!
Thanks for your input everyone.
Try this to force reload button.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([sender isKindOfClass:UIBarButtonItem.class]) {
UIBarButtonItem *button = sender;
self.navigationItem.rightBarButtonItem = nil;
self.navigationItem.rightBarButtonItem = button;
}
}

How to make a custom button that looks like a back button in NavigationBar? I mean the shape of the left side that is like an arrow

How to make a custom button that looks like a back button in NavigationBar? I mean the shape of the left side that is like an arrow.
In the sense how to set an image to back button?
Use UIButtonTypeCustom style.
Set required image (with shape of the left side that is like an arrow) to background property.
UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
backBtn.frame = CGRectMake(100,50,100,30);//set ur required frame
[backBtn setBackgroundImage:[UIImage imageNamed:#"backImage.png"] forState:UIControlStateNormal]; //Add back Like image
//use this button
The best way I've found is to use a stretchable button with a defined leftCapWidth to account for the pointy side of your button. That way if you ever need to change the label from "Back" "New Sales Customers" you don't need to re-export the background Image.
I even think they created a convenience extension for you:
var button = backButtonImage.StretchableButton(5, 0);
view.AddSubView(button);
http://idevrecipes.com/2010/12/08/stretchable-images-and-buttons/

problem to give colors for BarButtonItem

i have a ToolBar in my view controller.i need to show one icon in right side of the ToolBar.
so i added a BarButton item and displayed icon image there.but the is a problem with icon color.it displaying as black which is not looking good and also cant able to arrange Barbutton items on right side of the Toolbar.can any one tell me a good way to do it.please help me to arrange barbuttonitems on right side and provide a way to give colors to BarButtonItem.
Use below below change the color of UIToolBar.
//Give your choice of color.
myToolbar.tintColor = [UIColor darkGrayColor];
To align the right button you need to use a bar button of type UIBarButtonSystemItemFlexibleSpace Read SO post.
Aligning UIToolBar items

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.