如何在iOS 5中使用多个颜色文本的titleLabel制作UIButton?
问题描述:
让我们直接点。我需要一个带有两个彩色文字的UIButton
。我知道我可以使用`NSAttributeStrings属性来做到这一点,但它不适用于ios 5.如何在iOS 5中使用多个颜色文本的titleLabel制作UIButton?
那么我怎样才能使它成为ios 5.0
?
到现在我已经做到了这一点:
NSDictionary *firstAttributes = @{NSForegroundColorAttributeName: [UIColor blackColor]
};
NSDictionary *secondAttributes = @{NSForegroundColorAttributeName: [UIColor redColor]
};
NSString *club = NSLocalizedString(@"club_button_concat_text", @"club_button_concat_text");
NSAttributedString *myString = [[NSAttributedString alloc] initWithString:club attributes:secondAttributes];
答
AFAIK这并不适用于iOS < 6是可能的,你可以创建自定义视图,并使用drawRect:
方法的变通方法,画按钮UI。使用CoreText绘制属性字符串。重写touchesEnded:
方法来检测按钮触摸事件。
对于核心文字绘图,您可以按照此link。对于绘制按钮,请检查已经这样做的开源项目!希望这会有所帮助..
干杯!
Amar