2013-06-23 61 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]}