如何为按钮标题的一半着色

时间:2012-11-19 10:53:34

标签: objective-c ios

我有UIButton,我想只用红色的一半标题。这是我的按钮

NSString *title = AMLocalizedString(@"Remove", nil);
NSString *title1 = [NSString stringWithFormat:title, name ];
UIButton *rem = [UIButton buttonWithType:UIButtonTypeRoundedRect];
rem.frame = CGRectMake(140, 70, 175, 40);
[rem setTitle:title1 forState:UIControlStateNormal];

删除"Remove" = "Delete object %@";

我想仅用红色name

我该怎么做?

1 个答案:

答案 0 :(得分:1)

NSAttributeString UIButton's UILabel中使用iOS 6.0

yourbtn.titleLabel.attributedText = yourAttributeStringText;

请参阅NSAttributedStringInPractice链接,了解如何使用NSAttributeString

使用iOS 5.1lesser version时可能会使用:

UIButton's titleLabel

中使用TTTAttributedLabel