How can I style an MKUserTrackingBarButtonItem? - iphone

I'm adding the items programatically, but MKUserTrackingBarButtonItem doesn't seem to offer any way to style it to fit in with a BlackTranslucent UIToolBar...

MKUserTrackingBarButtonItem is a subclass of UIBarButtonItem which has a tintColor property. You can use this to make your button black.
MKUserTrackingBarButtonItem *userTrackingBarButtonItem =
[[MKUserTrackingBarButtonItem alloc] initWithMapView:self.mapView];
[self.navigationController.toolbar setBarStyle:UIBarStyleBlack];
[userTrackingBarButtonItem setTintColor:[UIColor blackColor]];
If you do set it to black like this, the user will never know when it's activated, as the blue color is never shown.

Related

ios7 xcode 5 GM: color of UIBarButtonItem and selected UISegmentedControl part on iOS 6 device keep default color

i'm porting now ios6 app to ios7 sdk (with Xcode 5 and mavericks) and i tried to change UIBarButtonItem color, here is what i try to do:
self.navigationController.navigationBar.tintColor
- make changes color for bar but not for items
[[UINavigationBar appearance] setTintColor:[UIColor greenColor]];
[[UIBarButtonItem appearance] setTintColor:[UIColor greenColor]];
- doesn't work, same wrong color
self.navigationItem.rightBarButtonItem.tintColor = [UIColor greenColor];
self.navigationItem.leftBarButtonItem.tintColor = [UIColor greenColor];
- doesn't work, same wrong color
UIBarButtonItem *close = [[UIBarButtonItem alloc]
initWithTitle:NSLocalizedString(#"Close",#"")
style:UIBarButtonItemStyleDone target:self
action:#selector(closeAddressBook:)];
close.tintColor = [UIColor greenColor];
- doesn't work, same wrong color
for self.filterSegment.tintColor = [UIColor greenColor] where UISegmentedControl *filterSegment;
i see unselected segment with correct color, but selected segment is a same wrong color.
any ideas?
Figured out what needs to be done, thanks to WWDC 2013 - Customizing Your App’s Appearance for iOS 7.
self.navigationController.navigationBar.tintColor = [UIColor redColor];
This will filter down into the other views in your app, so place on initial screen, and if you push to the next screen you will see that the back button is also red.
To change the navigation bar colour use
self.navigationController.navigationBar.barTintColor = [UIColor greenColor];
If you are making your app work for devices less than iOS7, you should check it responds to the selector
if([self.navigationController.navigationBar respondsToSelector:#selector(barTintColor)]) {
}
For iOS7 this code works for me when I wish to change the colour of an individual UIBarButtonItem:
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Title" style:UIBarButtonItemStyleBordered target:self action:nil];
[barButtonItem setTitleTextAttributes:#{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateNormal];
self.navigationItem.leftBarButtonItems = #[barButtonItem];
It might be a good idea to set the tintColor property on your app's UIWindow instance instead. If you've got a standard 'accent' colour you're using throughout your app, this will tint every control in the app with that colour.
1- In iOS 7, the tintColor property is no longer used for setting the color of the bar. Instead, use the barTintColor property to change the background color.You can insert the below code in the didFinishLaunchingWithOptions: of AppDelegate.m.
[[UINavigationBar appearance] setBarTintColor:[UIColor yellowColor]];
2- In iOS 7, all bar buttons are borderless. The back button is now a chevron plus the title of the previous screen (or just displays ‘Back’ as the button title if the title of the previous screen is nil). To tint the back button, you can alter the tintColor property, which provides a quick and simple way to skin your app with a custom color. Below is a sample code snippet:
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
self.navigationController.navigationBar.tintColor = [UIColor redColor];
This is the way to set the color for the backbutton.
Just a note for ppl who developed the app using IOS 6, we used the above code to set the Nav Bar Color, so by mistake if you did not remove the previous setting you will not see the change to the back button.
I finally figured out the way to solve this problem.
After setting the button, you need to wait 5-7 ms (in case of iPhone 5s).
UIBarButtonItem *button=[[UIBarButtonItem alloc]...
self.navigationItem.rightBarButtonItem=button;
[button performSelector:#selector(setTintColor:) withObject:[UIColor blueColor] afterDelay:0.1];
You shouldn't set the color before setting rightBarButtonItem. It should work for both iOS 6 & 7.

UINavigationBar Custom Title View

I am using iOS 5 UINavigationBar's UIAppearance protocol in order to customise all my navigation bars.
Here is my customisation function:
- (void)customizeApperance
{
[[UINavigationBar appearance] setTintColor:[UIColor clearColor]];
[[UINavigationBar appearance] setAlpha:0.7];
UIImageView *titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"title.png"]];
[[UINavigationBar appearance] setTitleView:titleView];
}
I have two problems:
The first is that the colour not appearing as clearColor but black. Any suggestions?
The title view is not appearing at all. Ray Wenderlich shows how to do that by adding a: [[rootViewController navigationItem] setTitleView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"miniLogo.png"]]] in applicationDidFinishLaunching. But the problem with this is that the title view would only be added in the root view controller. I am using a UINavigationController and when I tired to replace the rootViewController with navigationController (the name of my navigation controller in AppDelegate), I cannot see the title view at all. How can I fix that? Why isn't it working in customizeApperance()? Isn't the whole point of using appearance is to just create a title view once (as I did above the function) and have it global in all navigation bars? How can I achieve that?
[UIColor clearColor] is a fully transparent color (alpha = 0). Setting that as tint color makes the (black) background shine through. Perhaps you want [UIColor whiteColor] ?
titleView is a property of UINavigationItem, and each view controller has it's own navigationItem. Therefore you cannot set a title view globally. But you can set the background image of UINavigationBar with the appearance protocol, perhaps that helps:
[[UINavigationBar appearance] setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
Have you tried titleView.opaque = NO;? If that's set to YES (i.e. by default, since you're using initWithImage:), the drawing system will assume your view fills its entire bounds, and won't bother drawing anything that overlaps its frame.
setTitleView: is a method on NavigationItem. But you are calling it on navigation bar

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!

UISegmentedControl in Mail app

How do I get a UISegmentedControl that is like the one in the Mail App, so that it is the same colour as UIToolbar buttons (as if both segments were in the selected state).
I want to use the segmented control for exactly the same purpose as Mail.
(on the iPad, so a grey not blue color)
This is code from Apple Sample codes... NavBar and both the images used in the code..
you shoud be able to get exact same view as mail App.
// "Segmented" control to the right
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:
[UIImage imageNamed:#"up.png"],
[UIImage imageNamed:#"down.png"],
nil]];
[segmentedControl addTarget:self action:#selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segmentedControl.frame = CGRectMake(0, 0, 90, 30);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.momentary = YES;
defaultTintColor = [segmentedControl.tintColor retain]; // keep track of this for later
UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[segmentedControl release];
self.navigationItem.rightBarButtonItem = segmentBarItem;
[segmentBarItem release];
You seek the tintColor property!
When you use a UISegmentedControl you can change its tint color to any color you can dream up. So, if you added the UISegmentedControl in Interface Builder then you would style it in your - (void)viewWillAppear:(BOOL)animated method as such (assuming you had it hooked up to a #synthesized ivar:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Set the tintColor to match the navigation bar
self.mySegmentedControl.tintColor = [UIColor colorWithRed:.94 green:.94 blue:.94 alpha:1];
... do whatever else in your viewWillAppear ...
}
Now obviously you will want to play with the red, green, blue, and alpha's that I've put in the sample code above, but you can literally tint the UISegmentedController any color you would like (or make it as transparent as you would like), so it's just a matter of finding the RGBA values that look perfect to you.
Remember that per Apple's docs that the default value of this property is nil (no color). UISegmentedControl uses this property only if the style of the segmented control is UISegmentedControlStyleBar.
Good luck!
I dont know exactly what you mean.. but i believe the "UISegmentedControlStyleBar" as segmentedControlStyle could it be.
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar
You can set this property in the IB too! (It's the property called "style")
The style I'm looking for is undocumented: it is style 4.
It looks like he up/down control here: http://media.mobilemeandering.com/wp-content/uploads/2010/04/ipad-mail-message-2.png
(not my image btw)
It basically makes all segments look selected, it's intended for momentary pushes, and is effectively multiple tool bar buttons pushed up together.
So it can't be set in IB but must be set in code or manually in the nib/xib file, by opening the nib as a text file.
I'm not sure I exactly understand what you're trying to do, but I'll give it a shot.
The solution is not obvious, you need to use a UISearchDisplayController in order to get a matching UISearchBar and UISegmentedControl.
See the TableSearch sample code for an example.

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.