Attribute富文本使用方法
★★★Attribut富文本★★★
在UITextView和UILable的使用中很多的时候会用到富文本。
UITextView和UILable的区别在于:
★★★★UITextView 当文字大于一定的时候可以进行上下的滚动
★★★★UILable 可以设置长的`Lalbe.number = 0`来设置可以换行,但是当文字大于它整个尺寸的时候就会出现文字显示不完。
NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:str];
//格式调整
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
/**调行间距*/
style.lineSpacing = 10;
//字间距
[attStr addAttribute:NSKernAttributeName value:@5 range:NSMakeRange(0, [str length])];
//添加行间距
[attStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, [str length])];
//横竖排版 ---无效果
// [attStr addAttribute:NSVerticalGlyphFormAttributeName value:@1 range:NSMakeRange(0, [str length])];
//下画线
[attStr addAttribute:NSUnderlineStyleAttributeName value:@1 range:NSMakeRange(0, [str length])];
//边线宽度
[attStr addAttribute:NSStrokeWidthAttributeName value:@1 range:NSMakeRange(10, 10)];
//边线颜色
[attStr addAttribute:NSStrokeColorAttributeName value:[UIColor redColor] range:NSMakeRange(10, 10)];
//阴影--无效果
[attStr addAttribute:NSShadowAttributeName value:@4 range:NSMakeRange(20, 10)];
//下划线
[attStr addAttribute:NSStrikethroughStyleAttributeName value:@2 range:NSMakeRange(20, 10)];
[attStr addAttribute:NSStrikethroughColorAttributeName value:[UIColor redColor] range:NSMakeRange(20, 10)];
//字体背影色
[attStr addAttribute:NSBackgroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(45, 10)];
//字体颜色
[attStr addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(60, 10)];
//段落--无作用
[attStr addAttribute:NSParagraphStyleAttributeName value:@6 range:NSMakeRange(70, 80)];
Lable字间距设置
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.infoLabel.text attributes:@{NSKernAttributeName : @(2.5f)}];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(, self.infoLabel.text.length)];
[self.infoLabel setAttributedText:attributedString]; self.infoLabel.numberOfLines = ;
[self.infoLabel sizeToFit];
[self.scrollView addSubview:self.infoLabel];
实例请参考:
NSString *strP = self.contentTextView.text;
//去掉空格:"\t\t"
NSString *str = [strP stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
//创建富文本
NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:str]; //格式调整
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init]; //字间距
[attStr addAttribute:NSKernAttributeName value:@1.5f range:NSMakeRange(, [str length])]; //字体设置
[attStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:RHFixXFlaot()] range:NSMakeRange(, [str length])]; //换行行距
style.lineSpacing = ; //段落
[attStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(, [str length])]; //段落首行缩进
style.firstLineHeadIndent = ; self.contentTextView.attributedText = attStr;
具体的使用请参考[DEMO下载](https://github.com/marlonxlj/Attributing_Demo.git),更多的使用方法还需要您自己亲自去尝试。
欢迎阅读本文,如有错误之处,请指出我好及时做出调整,谢谢。如果对您有帮助请右上角Star!
PS:
Attribute富文本使用方法的更多相关文章
- 微信小程序中显示html富文本的方法
微信小程序中显示html富文本的方法 使用方法:git地址:https://github.com/icindy/wxParse 一.下载wxParse文件 二.在要引入的页面的js文件中,引入文件 j ...
- UILabel和UIbutton(富文本)封装方法
/** 方法说明:设置label的富文本属性 参数说明:contentStr富文本内容 textColor字体颜色 rangeSet设置字体颜色及大小的位置 */ - (UILabel *)backf ...
- 简易使用UILabel的富文本
简易使用UILabel的富文本 使用效果: 源码: NSString+YX.h NSString+YX.m // // NSString+YX.h // YXKit // // Copyrigh ...
- JAVA 集成 Ueditor 百度富文本编辑器
开发环境:一个简单的SpringMVC框架中,用百度富文本编辑器 ueditor 实现图片和文件的上传 官网地址:http://ueditor.baidu.com/website/ 需要使用到的2个文 ...
- C#Winform使用扩展方法自定义富文本框(RichTextBox)字体颜色
在利用C#开发Winform应用程序的时候,我们有可能使用RichTextBox来实现实时显示应用程序日志的功能,日志又分为:一般消息,警告提示 和错误等类别.为了更好地区分不同类型的日志,我们需要使 ...
- jquery cleditor 光标经常点不进去问题解决方法 bootstrap 富文本框 控件
cleditor 光标点不进去,原因是内嵌的html代码段 body没有赋值默认高度. 解决方法1.赋值options.bodyStyle 设置min-height值.缺点:不能跟随设备更新最低高度 ...
- 富文本,NSAttributedString,当需要改变的内容有相同的时候的解决方法
在开发的过程中可能会遇到富文本展示,例如:一行文本,前面是题后面是答案,题和答案用不同的颜色字体,但是答案的内容在题总也有,这时候用平常的方法就会展示错误,因为把题中的内容改变了颜色二实际答案却没有改 ...
- vue 使用v-html指令渲染的富文本无法修改样式的解决方法
最近的vue项目中遇到的问题:v-html渲染的富文本,无法在样式表中修改样式 解决方法: 把需要添加或重置的样式单独放在一个style标签里, 定义为全局样式,代码如下: <style> ...
- selenium自动化测试在富文本中输入信息的方法
第一次用selenium+python编写自动测试脚本,因为页面中插入了富文本编辑,开始怎么都无法输入进去,度娘好多方法都无效,分享踩坑的经历一是为了记录一下自己的成长,二是为了给同样摸索seleni ...
随机推荐
- iOS drewRect方法
You do not need to override this method if your view sets its content in other ways. By the time thi ...
- 动作手游实时PVP技术揭密(服务器篇)
前言 我们的游戏是一款以忍者格斗为题材的ACT游戏,其主打的玩法是PVE推图及PVP 竞技.在剧情模式中,高度还原剧情再次使不少玩家泪目.而竞技场的乐趣,伴随着赛季和各种赛事相继而来,也深受玩家喜爱, ...
- C#解析json文件的方法
C# 解析 json JSON(全称为JavaScript Object Notation) 是一种轻量级的数据交换格式.它是基于JavaScript语法标准的一个子集. JSON采用完全独立于语言的 ...
- Java Servlet规范
截自网址:http://blog.csdn.net/u010391029/article/details/46521051 JavaServlet Specification Version 2.3 ...
- CSS常用布局学习笔记
水平居中-行内元素 如果是文字和图片这类的行内元素,则在其父级元素上加上样式:text-align:center; 水平居中-定宽块元素 div{ width:100px; margin:0 auto ...
- Linux命令dos2unix 从windows转换到linux --- nuix2dos从linux转换到windows
dos2unix命令用来将DOS格式的文本文件转换成UNIX格式的(DOS/MAC to UNIX text file format converter).DOS下的文本文件是以\r\n作为断行标志的 ...
- python使用pdkdf2加盐密码
from werkzeug.security import generate_password_hash, check_password_hash pw = generate_password_has ...
- sql with as union all
WITH RPL (FId,Fname,Forder) AS ( SELECT ment.deptno,ment.deptname,ment.orderno FROM JTERP..fg_depart ...
- 关于C#调用非托管动态库方式的性能疑问
最近的项目中,因为一些原因,需要C#调用非托管(这里为C++)的动态库.网上喜闻乐见的方式是采用静态(DllImport)方式进行调用.偶然在园子里看到可以用动态(LoadLibrary,GetPro ...
- browsersync实现网页实时刷新(修改LESS,JS,HTML时)
var gulp = require("gulp"), less = require("gulp-less"), browserSync = require(& ...