NSAttributedString】的更多相关文章

iOS7以后,因为TextKit的强大,可以用NSAttributedString很方便的实现图文混排(主要是利用了NSTextAttachment). 关于Textkit的牛逼之处,可以参考objcio上的文章(https://objccn.io/issue-5-1/) 我用NSAttributedString仿写了一个知乎的输入框(低仿,就是有个功能而已),效果如图: demo在这里:(https://github.com/Phelthas/TEST_XMLCommon   的第四个)  …
NSAttributedString 叫做富文本,是一种带有属性的字符串,通过它可以轻松的在一个字符串中表现出多种字体.字号.字体大小等各不相同的风格,还可以对段落进行格式化,一般都是对可变富文本(NSMutableAttributedString)进行一些操作 一.NSMutableAttributedString 类的部分常用方法 // 在一定范围中添加单个文字属性 // 参数1:字符属性名 // 参数2:属性值 // 参数3:范围 - (void)addAttribute:(NSStrin…
注:通常的label用来现实普通的文字.但是,你常常会遇到这样的情况:一段文字中不仅有文字,也有图片,甚至文字中的某段文字与其他的文字的appearance不一致的情况,这样的一段文字就可以称得上是富文本了.label的attributedText属性就是用来接受这样的文本内容的. 场景 如图 若你遇到这样的需求,不妨考虑一下使用NSAttributedString了创建这样的文本.如果这段文字具有点击事件,实现方法有以下两种: 将这段文字设置为button的attributedTitle 将这…
最近经常遇到关于富文本的一些需求,特此封装了几个最常用的API分享给大家,但授之以鱼不如授之以渔,接下来会顺便谈谈NSAttributedString,确保你读了本篇文章能够自己封装关于富文本的API,本文封装API的示例Demo再此,拿去用吧!骚年们! 一.常用需求封装 需求:在我们日常开发中,某些句子中会有改变某些字颜色的需求,当然颜色一般而言就是为了着重强调,常为同一种颜色,所以下面代码是单纯改变一句话中的某些字的颜色 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15…
The HTML importer should not be called from a background thread (that is, the options dictionary includesNSDocumentTypeDocumentAttribute with a value of NSHTMLTextDocumentType). It will try to synchronize with the main thread, fail, and time out. Cal…
http://stackoverflow.com/questions/7611816/multi-line-nsattributedstring-with-truncated-text/10172794#10172794 Multi-line NSAttributedString with truncated text up vote14down votefavorite 8 I need a UILabel subcass with multiline attributed text with…
An NSAttributedString object manages character strings and associated sets of attributes (for example, font and kerning) that apply to individual characters or ranges of characters in the string. 这句话就是对这个类的一个最简明扼要的概括.NSAttributedString管理一个字符串,以及与该字符串…
标签: 以前看到这种字号和颜色不一样的字符串,想出个讨巧的办法就是“¥150”一个UILable,“元/位”一个UILable.今天翻看以前的工程,command点进UITextField中看到[attributedText]这个关键字,以前都没注意过UITextField还有这个属性,其实UITextView.UILable也有这个属性,iOS6就已经有了,说来惭愧,对此罚站1秒钟. NSAttributedString叫做富文本,是一种带有属性的字符串,通过它可以轻松的在一个字符串中表现出多…
直接调用系统的写起来比较麻烦,封装一下 因为要简单所以就写类方法 WJAttributeStyle 基类 ) {         ; i < styles.count; i ++) {         WJAttributeStyle *style = styles[i];         [attributeString addAttribute:style.attributeName                                 value:style.value     …
以前看到这种字号和颜色不一样的字符串,想出个讨巧的办法就是“¥150”一个UILabel,“元/位”一个UILabel.今天翻看以前的工程,command点进UITextField中看到[attributedText]这个关键字,以前都没注意过UITextField还有这个属性,其实UITextView.UILable也有这个属性,iOS6就已经有了,说来惭愧,对此罚站1秒钟. NSAttributedString叫做富文本,是一种带有属性的字符串,通过它可以轻松的在一个字符串中表现出多种字体.…
NSAttributedString 叫做富文本,是一种带有属性的字符串,通过它可以轻松的在一个字符串中表现出多种字体.字号.字体大小等各不相同的风格,还可以对段落进行格式化,一般都是对可变富文本(NSMutableAttributedString)进行一些操作 一.NSMutableAttributedString 类的部分常用方法 // 在一定范围中添加单个文字属性 // 参数1:字符属性名 // 参数2:属性值 // 参数3:范围 - (void)addAttribute:(NSStrin…
@于iOS6之前,需要使用NSMutableAttributedString当你需要导入:CoreText.framework框架的.但在iOS6 之后就不在须要了. - (void)testOfNSMutableAttributedStringAndNSAttributedString { /** * - (void)addAttribute:(NSString *)name value:(id)value range:(NSRange)range; * 主要方法 * name 属性名 * v…
因为iOS7新出的NSTextStorge是NSMutableAttributedString的子类.所以要用好NSTextStorage.首先要学好NSMutableAttributedString和NSAttributedString. 按个人的理解.NSAttributedString是一个带有属性的字符串,通过该类能够灵活地操作和呈现多种样式的文字数据. alignment //对齐方式   firstLineHeadIndent //首行缩进   headIndent //缩进   t…
http://www.bubuko.com/infodetail-382485.html 标签:des   class   style   代码   html   使用   问题   文件   数据 这篇文章是我的[iOS开发每日小笔记]系列中的一片,记录的是今天在开发工作中遇到的,可以用很短的文章或很小的demo演示解释出来的小心得小技巧.它们可能会给用户体验.代码效率得到一些提升,或是之前自己没有接触过的技术,很开心的学到了,放在这里得瑟一下.90%的作用是帮助自己回顾.记忆.复习. 测试组…
转载自: https://www.invasivecode.com/weblog/attributed-text-swift/   I have been talking quite a lot in the past about how to customize text in your app to improve the UI of your applications. Before iOS 6, Core Text was the only available option for de…
原文链接:http://www.jianshu.com/p/09f54730feaa 先看看所有的Key NSFontAttributeName; //字体,value是UIFont对象 NSParagraphStyleAttributeName;//绘图的风格(居中,换行模式,间距等诸多风格),value是NSParagraphStyle对象 NSForegroundColorAttributeName;// 文字颜色,value是UIFont对象 NSBackgroundColorAttri…
续前一篇:打开Voice Over时,CATextLayer的string对象兼容NSString和NSAttributedString导致的Crash(二解决思路2)ok,到这里已经能够锁定范围了,看看po $r0的打印结果:…
一.现象:iPhone真机打开Voice Over的情况下,iPhone QQ空间工程,Xcode 真机编译启动必Crash,main函数里面 NSSetUncaughtExceptionHandler 捕获到Exception:捕获异常函数: static void UncaughtExceptionHandler(NSException* exp) { QZLOG_ERROR(@"QZone UncaughtExceptionHandler Exception:%@, callStackSy…
NSAttributedString基本知识点介绍 1.初始化方法 - (instancetype)initWithString:(NSString *)str; - (instancetype)initWithString:(NSString *)str attributes:(nullable NSDictionary<NSString *, id> *)attrs; - (instancetype)initWithAttributedString:(NSAttributedString…
NSMutableAttributedString let testAttributes = [NSAttributedStringKey.foregroundColor: UIColor.blue, NSAttributedStringKey.backgroundColor: UIColor.yellow,NSAttributedStringKey.strikethroughStyle:1] as [NSAttributedStringKey : Any] let testAttributeS…
> 如何让Label等控件支持HTML格式的代码? 使用NSAttributedString: NSString *htmlString = @"<div>Tate<span style='color:#1C86EE;'><iOS Develop Tips></span>get <span style='color:#1C86EE;'>Tate_zwt</span> 打赏 <span style='color:#…
CHENYILONG Blog (CoreText框架)NSAttributedString 2 Fullscreen © chenyilong. Powered by Postach.io Blog…
NSAttributedString: http://blog.csdn.net/kmyhy/article/details/8895638 CTFramesetterSuggestFrameSizeWithConstraints: http://blog.sina.com.cn/s/blog_6308b98c0101byh9.html…
UILabel 和 UITextView 都能添加 NSAttributedString 属性字符串,通过这一点,可以实现带有属性的文字和文字内包含图片的文本内容展示. 效果如下:   1-初始化可变属性字符串 NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:textString]; 2-设置全局字体属性(设置字体大小为14) [attributedStr…
#import <CoreText/CoreText.h> #import "ViewController.h" @interface ViewController () @property(nonatomic, weak) IBOutlet UILabel *label1; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional…
它本身是一个Foundation框架的类, 但如果要使用它主要用到了UIKit框架中的NSAttributedString中的一些常量字符串 ------------------------------------------------------------------------------------------------------------ NSFontAttributeName:字体,是一个UIFont对象 NSParagraphStyleAttributeName:段落,是一…
ios NSAttributedString 具体解释 NSAttributedString能够让我们使一个字符串显示的多样化,可是眼下到iOS 5为止,好像对它支持的不是非常好,由于显示起来不太方便(至少没有在OS X上方便). 首先导入CoreText.framework,并在须要使用的文件里导入: #import<CoreText/CoreText.h> 创建一个NSMutableAttributedString: NSMutableAttributedString *attriStri…
1,最近项目中用到了一个功能,一个很好的功能.就是用户在搜索的时候,搜索结果出来后对你输入的关键字进行红色标记.这样用户就很请楚的看到自己输入什么后会出现什么样子的结果.还有一个功能是,现在有一段文字了,但是要对其中的某些字符串进行着色处理,这个时候NSAttibutedString起到了非常大的作用.以下是我写好的一段代码,各位可以拿去用,非常方便的处理好. #import <Foundation/Foundation.h> @interface NSAttributedString (Co…
属性字符串NSAttributedString 可以对字符串附加格式信息,由于对于对不同文本片段使用不同的格式,属性字符串类特别合适. IOS 6中对样式文本有了大改善,大部分主要的UIKit控件都允许使用属性字符串.举例UILable,只要创建一个属性字符串,然后赋值给标签的attributedText属性即可. - (IBAction)buttonPressed:(UIButton *)sender { //按钮标题 NSString *title = [sender titleForSta…
- (void)viewDidLoad {     [super viewDidLoad];          NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc] initWithString:@"測试富文本显示"] autorelease];     //为全部文本设置字体     [attributedString addAttribute:NSFontAttribute…