Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIBarButtonItem: how can I change the text shadow offset?

I'm trying to change the offset of the shadow behind the text in a UIBarButtonItem.

This is my code:

NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
[attributes setValue:[UIColor colorWithWhite:0.30 alpha:1.0] forKey:UITextAttributeTextColor];
[attributes setValue:[UIColor whiteColor] forKey:UITextAttributeTextShadowColor];
[attributes setValue:[NSValue valueWithUIOffset:UIOffsetMake(0.0, 0.0)] forKey:UITextAttributeTextShadowOffset];
[[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];

Changing the text color works. Changing the shadow color works. Changing the shadow offset doesn't seem to do anything.

Is something wrong with the way I'm doing this? I've also tried setting it directly, without the appearance proxy, but that didn't work either.

like image 625
Steven Vandeweghe Avatar asked Mar 30 '12 11:03

Steven Vandeweghe


1 Answers

I believe your code is correct though perhaps you expect something different from what it does. If I paste it into a test app and change the offset values to 10.0, 10.0 the shadow offset is visible for me. (iOS 5.0)

Here's a clip taken from the simulator while running what you posted.

like image 98
Phillip Mills Avatar answered Oct 22 '22 12:10

Phillip Mills