UIBarButtonItem:如何更改文本阴影偏移量?

时间:2012-03-30 11:29:42

标签: ios cocoa-touch uibarbuttonitem

我正在尝试更改UIBarButtonItem中文本背后阴影的偏移量。

这是我的代码:

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];

更改文字颜色有效。更改阴影颜色有效。更改阴影偏移似乎没有任何作用。

我这样做的方式有问题吗?我也试过直接设置它,没有外观代理,但这也不起作用。

2 个答案:

答案 0 :(得分:1)

我相信你的代码是正确的,虽然你可能期望与它的作用有所不同。如果我将其粘贴到测试应用程序并将偏移值更改为10.0,10.0,则可以看到阴影偏移。 (iOS 5.0)

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

答案 1 :(得分:0)

您的阴影UIOffset值为0.0,0.0,这实际上不会导致阴影。您需要在任何方向上将阴影偏移至少1个像素。例如。这会给你左下角的阴影。

[NSValue valueWithUIOffset:UIOffsetMake(-1.0, 1.0)]