0

我有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

我怎样才能做到这一点?

4

1 回答 1

1

用于. NSAttributeString_ UIButton's UILabel_iOS 6.0

yourbtn.titleLabel.attributedText = yourAttributeStringText;

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

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

在中使用TTTAttributedLabelUIButton's titleLabel

于 2012-11-19T10:59:32.600 回答