2013-06-23 43 views
2

我已经调整一个的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的文字阴影,而不诉诸改变它的形象?

回答

6

UIBarButtonItemUITextAttributeTextShadowOffset属性设置为UIOffsetMake(0.0, 0.0)

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

+0

谢谢!所以我想我应该使用 [followButton setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@“Helvetica”size:14.0],UITextAttributeFont,[NSValue valueWithCGSize:CGSizeMake(0.0,0.0)],UITextAttributeTextShadowOffset,nil] forState:UIControlStateNormal] ; 而不是第一部分,但它不会改变它,有什么问题? –

+1

根据'UITextAttributeTextShadowOffset'的文档,'NSValue'中包含的值应该是'UIOffset',而不是'CGSize'。所以你需要使用'[NSValue valueWithUIOffset:UIOffsetMake(0,0)]''。 – rmaddy

3

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

@{UITextAttributeTextShadowColor : [UIColor clearColor]}