gpt4 book ai didi

ios - 改变 "label.text"范围的颜色

转载 作者:行者123 更新时间:2023-11-29 10:43:45 26 4
gpt4 key购买 nike

iOS7 addAttribute:(NSString *)NSForegroundColorAttributeName value: 可以改变label.text的颜色但在 iOS6 中会崩溃

iOS6 addAttribute:(NSString *)kCTForegroundColorAttributeName value: 不能改变label.text.color

我该怎么办?

- (void)userNoPayCreateFreeLabel
{
UILabel *freeLabel = [[UILabel alloc] initWithFrame:CGRectMake(
0,
NAVIGATIONBAR_HEIGHT,
self.view.bounds.size.width,
28)];
NSString *text = @"购买课程将享有高质量答疑,你可免费体验3次";
freeLabel.attributedText = [self changeLableTextColorStr:text];
freeLabel.backgroundColor = [CommUtls colorWithHexString:@"#fdfbf1"];
freeLabel.font = [UIFont systemFontOfSize:13];
freeLabel.textAlignment = 1;
self.freeLabel = freeLabel;
[self.view addSubview:freeLabel];
}

- (NSMutableAttributedString *)changeLableTextColorStr:(NSString *)text
{
NSMutableAttributedString *aStr = [[NSMutableAttributedString alloc] initWithString:text];
NSRange range = NSMakeRange([aStr length] - 2, 1);
if (IsIOS7) {
[aStr addAttribute:(NSString *)NSForegroundColorAttributeName value:
(id)[UIColor redColor].CGColor range:range];
}
else {
[aStr addAttribute:(NSString *)kCTForegroundColorAttributeName value:
(id)[UIColor redColor].CGColor range:range];
}
return aStr;
}

最佳答案

试试这个,

[aStr addAttribute:NSStrokeColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, aStr.length)];
[aStr addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, aStr.length)];

关于ios - 改变 "label.text"范围的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23209864/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com