gpt4 book ai didi

iphone - 在 iOS 中更改句子部分文本的颜色

转载 作者:行者123 更新时间:2023-12-03 21:15:52 25 4
gpt4 key购买 nike

Possible Duplicate:
TTT attributed Label Multi- colored Font help

如何在 iPhone 中喜欢这张图片?任何人都可以帮助我。我应该使用核心动画还是文本核心还是其他? http://s7.postimage.org/qgbhw7c3v/Capture.png

最佳答案

    NSString *test = @"How can i Do that? (just only one string and don't devided into 2 part)";

CFStringRef string = (CFStringRef) test;
CFMutableAttributedStringRef attrString = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0);
CFAttributedStringReplaceString (attrString,CFRangeMake(0, 0), string);



/*
Note: we could have created CFAttributedStringRef which is non mutable, then we would have to give all its
attributes right when we create it. We can change them if we use mutable form of CFAttributeString.
*/




CGColorRef _red=[UIColor redColor].CGColor;

CFAttributedStringSetAttribute(attrString, CFRangeMake(0, 11),kCTForegroundColorAttributeName, _red);

注意 => 在项目中添加CoreText框架并导入。

关于iphone - 在 iOS 中更改句子部分文本的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13738149/

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