[英]How to color half of the button title
I have UIButton
and I would like to color red only half of the title.Here is my button 我有
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 is "Remove" = "Delete object %@";
删除为
"Remove" = "Delete object %@";
I would like to color red only name
我想将红色仅
name
How can I do that? 我怎样才能做到这一点?
use NSAttributeString
in UIButton's
UILabel
for iOS 6.0
. 在
iOS 6.0
UIButton's
UILabel
使用NSAttributeString
。
yourbtn.titleLabel.attributedText = yourAttributeStringText;
Refer NSAttributedStringInPractice link for how to use NSAttributeString
. 有关如何使用
NSAttributeString
请参见NSAttributedStringInPractice链接。
When using iOS 5.1
or lesser version
possibilty is to use: 使用
iOS 5.1
或lesser version
可以使用:
use TTTAttributedLabel in UIButton's titleLabel
使用TTTAttributedLabel中
UIButton's titleLabel
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.