UIBarButtonItem appearance setTitleTextAttributes does not affects UIControlStateDisabled state - ios5

Our designer asked me to use specific color for text of disabled UIBarButtonItems. That code I've used to implement this:
NSDictionary* textAttributes = [NSDictionary dictionaryWithObject: [UIColor blueColor]
forKey: UITextAttributeTextColor];
[[UIBarButtonItem appearance] setTitleTextAttributes: textAttributes
forState: UIControlStateDisabled];
But it doesn't changed text attributes.
I've tried this code with Normal state, tried to chage background for UIControlStateDisabled buttons with setBackgroundImage and all thouse experiments works perfectly. But this single combination: setTitleTextAttributes and UIControlStateDisabled doesn't do anything.
Google didn't give me any relevant answer about that specific combination.
Does anybody know other way to change color of disabled UIBarButtonItem or way to make setTitleTextAttributes work for diabled items?

You have to set it for both control state Normal and Disabled.
(2015-11-18 -- As of iOS 9.1 you must still set both.)

It's working fine for me with iOS 5.1. Perhaps it was a 5.0 bug.

Related

iOS 7 MPMoviePlayerController change name of Done button

In iOS 6 we change name of done button in MPMoviePlayerController next way:
id mpBarAppearance = [UIBarButtonItem appearanceWhenContainedIn:[MPMoviePlayerViewController class], nil];
[mpBarAppearance setTitle:#"ГОТОВО"];
[mpBarAppearance setTitlePositionAdjustment:UIOffsetMake(1.5f, 1.f) forBarMetrics:UIBarMetricsDefault];
[mpBarAppearance setTitlePositionAdjustment:UIOffsetMake(1.5f, 1.f) forBarMetrics:UIBarMetricsLandscapePhone];
Now in iOS 7 this crash app, under debbug it no raise exception and I cann't even understand why ?
It's because you can't use the appearance proxy to customise the title of UIBarButtonItems. Otherwise, all the bar buttons contained in the given parent would be named the same. You can customise other appearance parameters such as the background images, title position and so on.
The appearance proxy reference for UIBarButtonItem can be found here

Colours within a NSArray arrayWithObjects

I have a simple leader boards table for an iphone game that allows me to view the previous high scores however the background is black and therefore it is not visible. I am using the code:
[highscores addObject:[NSArray arrayWithObjects:#"Title",[NSNumber numberWithInt:5000],nil]];
Can I change the colour easily?
All help greatly appreciated, I expect it is simple but google is coming back with little.
Thanks in advanced!
changing the color is not related with an Array.Its related with the container who displays the Title .
you may binding the Title string to any UILabel.
So you have to set the textColor property to white.
Eg: label1.textColor = [UIColor whiteColor];
To make the UILabel white, remove this code:
[label1 setRGB:0 :0 :0];
And add do this instead:
[label1 setTextColor:[UIColor whiteColor]];
Let me know if this helps you. Posting your code definitely helps. You are doing great at age 14, so keep it up.

How to increase the size of UITabBarItem in iphone?

I want to increase the Text size of UITabBarItem in my application.It is not visible clearly with its default color and size.
I tried this code but give me error -->UITabBar for instant message does not declare method with selector 'setTitleTextAttributes'.
Does any know how to do it?
[yourTabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[NSValue valueWithUIOffset:UIOffsetMake(0,0)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:#"Helvetica" size:18.0], UITextAttributeFont, nil]
forState:UIControlStateNormal];
I think the default size is fully conveninet for the user. Anyway you want, maybe you should make your own <Tabbar> with UIView, UIButtons and UITabbar-style images.
setTitleTextAttributes:forState: is only available in iOS 5.0 or later. Please refer to UIBarItem Class Reference (UITabBarItem is subclass of UIBarItem). For prior versions of iOS, I think you'd better create your own customized tab bar.
And you may also want to try other methods from the answers in Changing font size of tabbaritem.
For that you should create dynamic tab bar using UITabbar class.
.Using this You can allow own size text ,image,color.

UIToolbar tint on iOS 4

just switched to iOS 4 on my iPhone 3GS and some of my apps broke.
One issue I had is that I had a UIToolbar with some buttons, tinted to pink, that worked well on the 3.1.3 OS. After upgrading to iOS 4, the toolbar was still tinted, but the buttons it contained were no longer affected by the tint. The toolbar was pink while the buttons were regular-blue.
Looked around for it on the net, but found no reference of such a thing.
Anyone knows what broke in the process?
(must be frank here - I knew the answer before posting, just didn't know how to load this data to StackOverflow. Thought the solution I found was valuable for others, so wanted to post it here. I'm new here, so please no harsh critics :) )
So eventually the problem resulted from, AFAICT, a change in behavior in the OS.
As stated the tint code worked before the upgrade and was written like this:
// Toolbar content
NSArray *items=[NSArray arrayWithObjects: ... ]; // PSEUDO CODE HERE
[toolbar setItems:items];
// Add tint
toolbar.tintColor = [UIColor colorWithRed:0.83 green:0.43 blue:0.57 alpha:0.5];
What I needed to do, was just reverse the order of things:
// Add tint
toolbar.tintColor = [UIColor colorWithRed:0.83 green:0.43 blue:0.57 alpha:0.5];
// Toolbar content
NSArray *items=[NSArray arrayWithObjects: ... ]; // PSEUDO CODE HERE
[toolbar setItems:items];
(If you created UIToolbar in Interface Builder, you can change it's tint there, and that applies for the buttons as well).
I guess the tint updated all buttons before iOS 4, while in iOS 4 it doesn't and when adding buttons, they check for existing tint. But this is just a guess. The solution works anyhow..
Hope this helps someone, and that I didn't violate any sacred SO rules...
Cheers!
Well, it seems more like an OS bug than a feature, since navigation bars do change their item's color when you set their tintColor.
We've found that if you change the item's style, it refreshes their color as a side effect. Doing the following worked in our case. The original buttons are bordered, so we change them to plain and set them to bordered again. You may do a more complicated and generic code that saves the current style, sets another one and then switchs back. I am just to lazy to do that. :D Anyway, you get the idea.
toolbar.tintColor = //<some dynamically obtained UIColor>
// Workaround to properly set the UIBarButtonItem's tint color in iOS 4
for (UIBarButtonItem * item in toolbar.items)
{
item.style = UIBarButtonItemStylePlain;
item.style = UIBarButtonItemStyleBordered;
}
Regards,
Rula.

Change the color of a Tabbar on the iPhone

Our designers want to change the color of the default UITabBar. Of course they do.
They want the background to be green, and the icon highlights to be white, as opposed to the black/blue default color scheme.
Anyone have any experience or suggestions to do this?
You have to subclass the UITabBarController and implement custom drawing.
Check out this SO question. Changing Tint / Background color of UITabBar
Since iOS5 is released, you can now use the property tintColor.
i.e.:
tabBar.tintColor = [UIColor greenColor];
I have try this one and its working for me!!!
[self.TabBarController.tabBar setTintColor:[UIColor colorWithRed:0.1294 green:0.5686 blue:0.8353 alpha:1.0]];
[self.TabBarController.tabBar setTintColor:[UIColor "YOUR COLOR"];
Hope it'll help you also!!!
iOS 5.0 fixes this issue but the solution is under NDA. Look up UITabBar in your documentation for an EASY way to do what you want to do.
Be careful. If your app is going for submission to the app store, Apple may reject it if you're modifying their prescribed color scheme.
Theres a useful link here: http://duivesteyn.net/2010/01/16/iphone-custom-tabbar-background-image/
This can be done with a little private API hacking.