简体   繁体   English

如何给按钮标题的一半上色

[英]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.1lesser version可以使用:

use TTTAttributedLabel in UIButton's titleLabel 使用TTTAttributedLabelUIButton's titleLabel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM