UIBarButtonItem normal and pressed states switched? - iphone

I created a toolbar with a translucent black style like so:
UIToolbar *toolbar = [UIToolbar new];
toolbar.barStyle = UIBarStyleBlack;
toolbar.translucent = YES;
I created a button item for it:
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithImage:nil
style:UIBarButtonItemStyleBordered
target:self
action:#selector(mySelector:)];
I noticed that the button when in normal state appears light grey and turns to full black only when I press on it. This seems to be the opposite of how it should function (e.g. Photo app). I'd like it do be black in normal state and lighter when pressed. What am I missing?

Change the barstyle to UIBarStyleBlackTranslucent, as dumb as it sounds, and I believe it returns it to normal.

Related

Textfield overlapping with UIView's text on keyboard

I am working on iOS application and in one of the view I have to load user comments as well as let them post comments. Everything looked fine until keyboard appears on user taps on text field to enter comments. The text on the UIView is overlapping with textfield as shown below.
Thank you for taking a look.
In iOS it is customary to add all view elements within a keyboard-enabled view into a UIScrollView. This way, when the keyboard slides up - the other elements slide up with it to avoid being obstructed.
Lucky for you, someone has implemented a UIScrollView that avoids the keyboard automatically, so all you need is to insert your view elements in to one of these and everything should work perfectly.
https://github.com/michaeltyson/TPKeyboardAvoiding
Assuming that the UITextField and UIButton("Post") move up when the user taps on the textField you should move everything else above it up an equal distance at the same time.
With more than just a little bit of text on the screen, you will have to go with UIScrollView. You can then use the [self.scrollView setContentOffset:CGPointMake(0, offset) animated:YES]; to move up (or down) your text in relation to the keyboard.
Use inputAccessoryView for your post button and UITextField.
Like this:
-(void)addAccessoryViewOnTextView
{
UIToolbar *keyboardHeaderView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 1024, 39)];
keyboardHeaderView.tintColor = [UIColor blackColor];
/* Here use your post button and textfield.
UIBarButtonItem *nextBtn= [[UIBarButtonItem alloc]initWithTitle:#"Next" style:UIBarButtonItemStyleDone target:self action:#selector(nextEvent:)];
UIBarButtonItem *prevBtn= [[UIBarButtonItem alloc]initWithTitle:#"Previous" style:UIBarButtonItemStyleDone target:self action:#selector(prevEvent:)];
UIBarButtonItem *doneBtn= [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(doneEvent:)];*/
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[keyboardHeaderView setItems:[NSArray arrayWithObjects: doneBtn,flexibleSpace,prevBtn, nextBtn, nil]];
[yourTextField setInputAccessoryView:keyboardHeaderView];
keyboardHeaderView = nil;
}
And call this method in viewDidLoad or anywhere your UITextField initializes.

Changing colour of NavigationBar and Barbutton

I have a UINavigationBar, and the colour of it is purple. I have added a uibarbutton of the left of it. It too is purple, But what i want it to look is black.
1.) I only need the navigationbar to remain purple, everything else uibarbutton, navigation back button (when we go from one view to another we get a arrow shaped back button) should be black.
I used the interface builder to change the colour of the uibarbutton (setTint), but when i ran it on my iOS 4.3 device it still appears as purple.
I tried cleaning, building and re-installing the app nothing hapence.
Just set it up like this
// Loads the view
-(void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
self.navigationItem.leftBarButtonItem = [UIBarButtonItem* settings = [[UIBarButtonItem alloc] initWithTitle:#"Settings" style:UIBarButtonItemStylePlain target:self action:#selector(settingsButtonEvent:)]];
[self.navigationItem.leftBarButtonItem setTintColor:[UIColor redColor]];
// some more code for your view
}
You can't set a different tintColor for both objects, but you can set an image as the button background.
I hope it helps you!

Problems adding a UIBarButtonItem programmatically or editing one inserted via IB

I'm working on project that uses a tab bar at the bottom to flip through 5 sections of my app. One of these sections loads a map view which then spawns a web view. This was done with Round Rect Buttons at first, but they got in the way of the views, so I decided to switch to a navigation bar. In Interface Builder I inserted a navigation item and within it two Bar Button Items (left and right side). I've gotten the functionality for both button to work by control dragging from file's owner to fire the method associated with each button. This works fine and launches my web view, but what I would like to be able to do and have yet to figure out how to so far, is changing one of the buttons to a "done" or "back" button once in the web view. I've tried creating both buttons programmatically but neither would appear. This is the code I tried using to accomplish this...
UIBarButtonItem *updatePosition = [[UIBarButtonItem alloc] initWithTitle:#"Update Position"
style:UIBarButtonItemStylePlain target:self action:#selector(findMe)];
self.navigationItem.leftBarButtonItem = updatePosition;
[updatePosition release];
When I run the app, the button does not show up on the navigation item I inserted using Xcode. The only way I can get the buttons to appear is by inserting them with Interface Builder as I previously mentioned. But then I can not change the left button to a "back" or "done" button once I've brought up the new view. I tried running this code to change the style of the button on the UIBarButtonItem I inserted using IB with this code
self.navigationItem.leftBarButtonItem.style = UIBarButtonItemStyleDone;
But to no avail.
Here are some Utility methods to help you along the way:
+ (UIBarButtonItem *)setRightBarButtonItem:(SEL)action target:(id)sender withImage:(NSString *)imageName {
UIImage *buttonImage = [UIImage imageNamed:imageName];
UIBarButtonItem *buttonItem = [[[UIBarButtonItem alloc] initWithImage:buttonImage
style:UIBarButtonItemStyleBordered
target:sender
action:action] autorelease];
return buttonItem;
}
+ (UIBarButtonItem *)setRightBarButtonItem:(SEL)action target:(id)sender withBarButtonSystemItem:(UIBarButtonSystemItem)systemItem {
UIBarButtonItem *buttonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:systemItem
target:sender
action:action] autorelease];
return buttonItem;
}
Usage:
// Done button.
self.navigationItem.rightBarButtonItem = [Utility setRightBarButtonItem:#selector(doneTapped:) target:self withBarButtonSystemItem:UIBarButtonSystemItemDone];

UIBarButton does not have a 'press' animation

I have a UIView that I am loading and it has a navigation bar with a 'Done' barButton. When I leave the navigation bar the default color, everything is fine. When I make it have a black tint, the 'Done' button works fine but it does not have the pressing animation that buttons usually have. It doesn't look as thought the button is being pressed. Does anyone know why this is?
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle: NSLocalizedString(#"Done", #"")
style:UIBarButtonItemStyleDone
target:self
action:#selector(donePressed:)]
autorelease];
Thank you so much!
[UIColor blackColor] does not supply a second color for the push effect. Your best best bet is to use darkGreyColor on the navigationBar or if you really need black then you'll have to animate this yourself.
I've heard that the reason black doesn't have a second color is because there is no color darker than black.

UIBarButtonItem black instead of white

I have that Navigation Controller and I'm adding 1 button by code this way:
UIBarButtonItem *configButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"config.png"] style:UIBarButtonItemStyleBordered target:self action:#selector(showConfigWindow)];
self.navigationItem.leftBarButtonItem = configButton;
It's working right but the icons are black instead of white!!
If I use this:
UIBarButtonItem *configButton = [[UIBarButtonItem alloc] initWithTitle:#"Settings" style:UIBarButtonItemStyleBordered target:self action:#selector(showConfigWindow)];
The text is showed properly in white.
The icons are ok cause I'm using them through interface builder and they show right.
UIBarButtonItem renders images in grayscale according to the images alpha value. So, if your image is fully opaque, then it will always render black, no matter what color the source image is, but if your image is transparent, it will render some shade of grey.
In order to render it fully white, or a color, you need to create a custom UIBarButtonItem. See Can I have a UIBarButtonItem with a colored image? for details