删除UIBarButtonItem文本阴影

时间:2013-06-23 23:55:31

标签: ios objective-c uibarbuttonitem

我已使用

调整了UIBarButtonItem以使用自定义字体和颜色属性
self.followButton = [[[UIBarButtonItem alloc]

                             initWithTitle: NSLocalizedString(@"TWITTER_FOLLOW_BUTTON_TEXT", nil)
                             style:UIBarButtonItemStylePlain
                             target:self
                             action:@selector(handleFollowButtonPressed:)]
                            autorelease];  

[self.followButton setBackgroundImage:[UIImage new] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];  

[followButton setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIFont fontWithName:@"Helvetica" size:14.0], UITextAttributeFont,nil] forState:UIControlStateNormal];  

NSDictionary *attributes = @{UITextAttributeTextColor : [UIColor colorWithRed:1 green:0.176 blue:0.333 alpha:1 /*#ff2d55*/ ]};

    [followButton setTitleTextAttributes:attributes
                            forState:UIControlStateNormal]; 

获得

的外观

enter image description here

如何删除buttonitem的文本阴影,而无需更改图像?

2 个答案:

答案 0 :(得分:6)

UIBarButtonItem的{​​{1}}属性设置为UITextAttributeTextShadowOffset

您需要将UIOffsetMake(0.0, 0.0)存储在UIOffset对象中:NSValue

答案 1 :(得分:3)

或者你可以将UITextAttributeTextShadowColor设置为[UIColor clearColor]

@{UITextAttributeTextShadowColor : [UIColor clearColor]}