简易使用UILabel的富文本】的更多相关文章

简易使用UILabel的富文本 使用效果: 源码: NSString+YX.h    NSString+YX.m // // NSString+YX.h // YXKit // // Copyright (c) 2014年 Y.X. All rights reserved. // #import <Foundation/Foundation.h> #import "ConfigAttributedString.h" @interface NSString (YX) // 创…
UILabel的富文本格式设置 1.实例化方法和使用方法 实例化方法: 使用字符串初始化 - (id)initWithString:(NSString *)str; 例: NSMutableAttributedString *AttributedStr = [[NSMutableAttributedStringalloc]initWithString:@"今天天气不错呀"]; - (id)initWithString:(NSString *)str attributes:(NSDict…
先描述一下问题,项目中用到了UILabel去显示一段富文本文字,超过label显示区域部分,省略号处理. 但是当设置好 attributedText 给label之后,显示出的效果是文字被切割了,并没有省略号处理 原因就是给label赋值attributeText的时候,之前设置的 lineBreakMode 会失效,所以出现上述的问题. 解决办法就是,在设置完attributeText的时候,重新设置一下lineBreakMode,问题完美解决.…
实例化方法和使用方法 实例化方法: 使用字符串初始化 - (id)initWithString:(NSString *)str; 例: NSMutableAttributedString *AttributedStr = [[NSMutableAttributedStringalloc]initWithString:@"今天天气不错呀"]; - (id)initWithString:(NSString *)str attributes:(NSDictionary *)attrs; 字典…
之前文本整理有一点乱,这边重新整理一下,下面是效果图,一共两个UILabel, 富文本整理: /*NSForegroundColorAttributeName设置字体颜色,对象UIColor; NSParagraphStyleAttributeName设置段落格式,对象NSMutableParagraphStyle; NSFontAttributeName设置字体,对象UIFont; NSBackgroundColorAttributeName设置背景颜色,对象UIColor; NSKernAt…
若想对UILabel添加图片,那么就需要使用NSMutableAttributedString来定义先定义一个普通的label UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(, , self.view.frame.size.width-, )]; lab.numberOfLines = ; [self.view addSubview:lab]; 然后对其定义 //创建富文本 NSMutableAttributedString *a…
1.NSKernAttributeName: @10 调整字句 kerning 字句调整 2.NSFontAttributeName : [UIFont systemFontOfSize:_fontSize] 设置字体 3.NSForegroundColorAttributeName :[UIColor redColor] 设置文字颜色 4.NSParagraphStyleAttributeName : paragraph 设置段落样式 5.NSMutableParagraphStyle *pa…
好久没写随笔了,因为最近比较忙,小公司基本都是一个前端干所有属于和部分不属于前端的事情,所以就没空弄了,即使想分享,也因为没有时间和精力就搁置了. 这周周六日休息,正好时间比较充裕(ps:目前处在单休中...),就分析了以下bootstrap-wysiwyg的源码,虽然只有200多行,但是本人js水平还是欠佳,所以大概用了一天的时间(ps:可怜我偶尔的双休还是变成了单休),对bootstrap-wysiwyg的源码进行了解读和部分的注释,在这里放出来,给需要的人,毕竟不是人人都喜欢百度的编辑器的…
本文转载至 http://www.jianshu.com/p/5d24d22f99c3 富文本 NSString *str = @"人生若只如初见,何事秋风悲画扇.\n等闲变却故人心,却道故人心易变.\n骊山语罢清宵半,泪雨霖铃终不怨.\n何如薄幸锦衣郎,比翼连枝当日愿."; NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:str]; attrStr添加字体和设…
要加载html字符串,用人说,直接用webView啊!但是,有时候我们只需要显示2行文字,如此少的内容却要在复杂的UI排版中加入一个占用资源较多的webview,得不偿失.这里要说的是,我们其实可以用label即可加载html字符的,用富文本转一下html字符串即可. //创建UILabel _Test_Lbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 200, 200)]; _Test_Lbl.backgroundColor =…