StyleString 类
富文本字符串,即带属性的字符串,除了内容之外会携带这些内容的展示样式
变量
_priveta_class_name : string
name : string
方法
fontName
设置字体名称
@note Android的这个接口,系统要求api28以上,Android版本8.2以下的手机都不生效
参数
- fontName : string 字体名称,如平方字体:PingFangSC-Regular,我们可以通过s = StyleString(); s:fontName('PingFangSC-Regular')语句来设置字体
返回值
setFontNameForRange
给指定内容设置字体
@note 如果此方法与setFontName同时使用,应先调用fontName方法,并且Android的这个接口,系统要求api28以上,Android版本8.2以下的手机都不生效
参数
- fontName : string 字体名称,如平方字体:PingFangSC-Regular
- index : number 指定范围的起始位置索引
- length : number 指定范围的字符长度
返回值
setFontSizeForRange
为指定范围内的字符设置字体大小
@note 如果此方法与setFontSize同时使用,应先调用setFontSize方法
参数
- fontSize : number 字体大小
- index : number 指定范围的起始位置索引, 从1开始
- length : number 指定范围的字符长度
返回值
fontSize
为字符串设置字体大小
参数
- fontSize : number 字体大小
返回值
fontStyle
字体样式
参数
返回值
setFontStyleForRange
给部分内容设置字体样式
@note 如果此方法与setFontStyle同时使用,应先调用fontStyle方法
参数
- fontStyle : number 字体样式,见FontStyle
- index : number 指定范围的起始位置索引, 从1开始
- length : number 指定范围的字符长度
返回值
fontColor
字体颜色
参数
返回值
setFontColorForRange
给部分内容设置颜色
@note 如果此方法与fontColor同时使用,应先调用fontColor方法
参数
- fontColor : Color 背景颜色:Color(r,g,b,a)具体参见:Color
- index : number 指定范围的起始位置索引, 从1开始
- length : number 指定范围的字符长度
返回值
backgroundColor
背景颜色
参数
返回值
setBackgroundColorForRange
给部分内容设置背景颜色
@note 如果此方法与backgroundColor同时使用,应先调用backgroundColor方法
参数
- color : Color 背景颜色:Color(r,g,b,a)具体参见:Color
- index : number 指定范围的起始位置索引, 从1开始
- length : number 指定范围的字符长度
返回值
underline
设置下划线
@note
参数
- style : UnderlineStyle 下划线样式UnderlineStyle
返回值
setUnderlineForRange
给部分内容设置下划线
@note 如果此方法与underline同时使用,应先调用underline方法
参数
- style : UnderlineStyle 下划线样式UnderlineStyle
- index : number 指定范围的起始位置索引, 从1开始
- length : number 指定范围的字符长度
返回值
showAsImage
以Image的形式展示,常用于图文混排
以Image的形式展示,前提是当前内容为图片网络路径或本地路径,且以图片形式展示后,背景色,下划线,字体等样式无法设置
@note 使用场景:用于向字符串中间插入图片进行展示
参数
- size : Size 图片大小
返回值
- 返回图片是否设置成功 : boolean
append
尾部追加StyleString
参数
- styleString : StyleString 追加的富文本字符串
返回值
calculateSize
计算显示该内容需要的最小尺寸
@note 此方法在iOS上算的不准,可能导致iOS上 用来设置label宽度时,文字被截断。 iOS上建议使用StringUtil:sizeWithContentFontSize方法; 另外,如果是用于 label 布局,推荐使用线性布局。
参数
- maxWidth : number 限定显示当前内容的最大宽度
返回值
- 返回显示当前内容所需要的最小尺寸 : Size Size)
setText
设置文本内容
参数
- content : string 文本内容