gpt4 book ai didi

苹果手机/iPad : How exactly use NSAttributedString?

转载 作者:行者123 更新时间:2023-12-03 18:08:27 25 4
gpt4 key购买 nike

是的,很多人都在谈论 iPhone/iPad 中的富文本,并且很多人都知道 NSAttributedString

但是如何使用NSAttributedString?我找了好久,没有任何线索。

我知道如何设置NSAttributedString,那么我应该怎样做才能在iPhone/iPad上以富文本形式显示文本?

官方文档说它应该与CoreText.Framework一起使用,这是什么意思?

有没有这样简单的方法?

NSAttributedString *str;
.....
UILabel *label;
label.attributedString = str;

最佳答案

从 iOS 6.0 开始你可以这样做:

NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Hello. That is a test attributed string."];
[str addAttribute:NSBackgroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(3,5)];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(10,7)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:20.0] range:NSMakeRange(20, 10)];
label.attributedText = str;

关于苹果手机/iPad : How exactly use NSAttributedString?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3786528/

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