作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
是的,很多人都在谈论 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/
我是一名优秀的程序员,十分优秀!