gpt4 book ai didi

ios - 我如何在 IOS 中使用 HTML.fromhtml?

转载 作者:行者123 更新时间:2023-11-28 20:24:36 25 4
gpt4 key购买 nike

我想发出这样的 NSString 通知:“你必须支付 4.00 美元。”。钱是红色的。在 Android 中,我可以使用 HTML.formhtml 来做。但我不知道该怎么做它在 IOS 中。谁可以帮助我?

最佳答案

试试这段代码

CATextLayer *aTextLayer_= [[[CATextLayer alloc]init] autorelease];
aTextLayer_.frame = CGRectMake(10, 100, 300, 50);
aTextLayer_.backgroundColor=[UIColor clearColor].CGColor;
aTextLayer_.foregroundColor = [[UIColor redColor] CGColor];
aTextLayer_.alignmentMode=kCAAlignmentCenter;
aTextLayer_.contentsScale = [[UIScreen mainScreen] scale];
aTextLayer_ .wrapped=YES;
[aTextLayer_ setAlignmentMode:kCAAlignmentLeft];

UIFont *smallFont = [UIFont systemFontOfSize:25];
CTFontRef ctSmallFont = CTFontCreateWithName((CFStringRef)smallFont.fontName, smallFont.pointSize, NULL);

UIFont *boldFont = [UIFont systemFontOfSize:25];
CTFontRef ctBoldFont = CTFontCreateWithName((CFStringRef)boldFont.fontName, boldFont.pointSize, NULL);

CGColorRef cgColor = [UIColor greenColor].CGColor;
CGColorRef cgColor1 = [UIColor redColor].CGColor;

NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
(id)ctSmallFont, (id)kCTFontAttributeName,
cgColor, (id)kCTForegroundColorAttributeName, nil];

NSDictionary *subattributes = [NSDictionary dictionaryWithObjectsAndKeys:
(id)ctBoldFont, (id)kCTFontAttributeName,
cgColor1, (id)kCTForegroundColorAttributeName, nil];
CFRelease(ctBoldFont);
NSString *subString=@"You must pay 4.00 dollar.";
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:subString attributes:attributes];

[attrStr addAttributes:subattributes range:NSMakeRange(13,4)];
aTextLayer_.string=attrStr;
[self.view.layer addSublayer:aTextLayer_];

enter image description here

关于ios - 我如何在 IOS 中使用 HTML.fromhtml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14432200/

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