AutoLua2AutoLua2
  • 快速开始
  • 介绍
  • 自动化API

    • 图色相关
    • 模拟相关
    • 节点相关
    • 界面相关
    • 其他
  • 界面API
  • 快速开始
  • 介绍
  • 自动化API

    • 图色相关
    • 模拟相关
    • 节点相关
    • 界面相关
    • 其他
  • 界面API
  • 自动化API

    • 图色相关

      • 全局
      • Bitmap
      • FindOrder
    • 模拟相关

      • 全局
      • Pointer
      • KeyCode
    • 节点相关

      • 全局
      • UiObject
      • UiSelector
    • 交互相关

      • 全局
      • UI
      • FloatView
      • FloatController
      • LayoutParams
      • LayoutParamsFlag
    • 其他
  • UI的API

    • 全局变量
    • 视图

      • View 类
      • window 类
      • Label 类
      • ImageButton 类
      • EditTextView 类
      • ScrollView 类
      • LinearLayout 类
      • Alert 类
      • Toast 类
      • Dialog 类
      • Switch 类
      • TabSegmentView 类
      • TableView 类
      • TableViewAdapter 类
      • TableViewAutoFitAdapter 类
      • CollectionView 类
      • CollectionViewAdapter 类
      • CollectionViewAutoFitAdapter 类
      • CollectionViewLayout 类
      • WaterfallView 类
      • WaterfallAdapter 类
      • WaterfallLayout 类
      • ViewPager 类
      • ViewPagerAdapter 类
    • 动画
    • 数据

      • Map 类
      • Array 类
      • Point 类
      • Size 类
      • Rect 类
      • Color 类
      • StyleString 类
    • 工具

      • Loading 类
      • Http 类
      • System 类
      • Timer 类
      • MBit 类
      • File 类
      • Application 类
      • Navigator 类
      • PreferenceUtils 类
      • TypeUtils 类
      • StringUtil 类
      • NetworkReachability 类
      • GlobalEvent 类
      • Clipboard 类
      • CornerManager 类
    • 枚举

      • ContentMode 枚举
      • TextAlign 枚举
      • BreakMode 枚举
      • FontStyle 枚举
      • UnderlineStyle 枚举
      • RepeatType 枚举
      • InterpolatorType 枚举
      • AnimType 枚举
      • EditTextViewInputMode 枚举
      • ReturnType 枚举
      • ScrollDirection 枚举
      • StatusBarStyle 枚举
      • RectCorner 枚举
      • LinearType 枚举
      • Gravity 枚举
      • MeasurementType 枚举
      • ValueType 枚举
      • GradientType 枚举
      • TabSegmentAlignment 枚举
      • NetworkState 枚举
      • CachePolicy 枚举
      • ResponseKey 枚举
      • ErrorKey 枚举
      • EncType 枚举

StyleString 类

富文本字符串,即带属性的字符串,除了内容之外会携带这些内容的展示样式

变量

_priveta_class_name : string

name : string

方法

fontName

设置字体名称

@note Android的这个接口,系统要求api28以上,Android版本8.2以下的手机都不生效

参数

  • fontName : string 字体名称,如平方字体:PingFangSC-Regular,我们可以通过s = StyleString(); s:fontName('PingFangSC-Regular')语句来设置字体

返回值

  • : StyleString

setFontNameForRange

给指定内容设置字体

@note 如果此方法与setFontName同时使用,应先调用fontName方法,并且Android的这个接口,系统要求api28以上,Android版本8.2以下的手机都不生效

参数

  • fontName : string 字体名称,如平方字体:PingFangSC-Regular
  • index : number 指定范围的起始位置索引
  • length : number 指定范围的字符长度

返回值

  • : StyleString

setFontSizeForRange

为指定范围内的字符设置字体大小

@note 如果此方法与setFontSize同时使用,应先调用setFontSize方法

参数

  • fontSize : number 字体大小
  • index : number 指定范围的起始位置索引, 从1开始
  • length : number 指定范围的字符长度

返回值

  • : StyleString

fontSize

为字符串设置字体大小

参数

  • fontSize : number 字体大小

返回值

  • : StyleString

fontStyle

字体样式

参数

  • fontStyle : FontStyle 字体样式见FontStyle

返回值

  • : StyleString

setFontStyleForRange

给部分内容设置字体样式

@note 如果此方法与setFontStyle同时使用,应先调用fontStyle方法

参数

  • fontStyle : number 字体样式,见FontStyle
  • index : number 指定范围的起始位置索引, 从1开始
  • length : number 指定范围的字符长度

返回值

  • : StyleString

fontColor

字体颜色

参数

  • fontColor : Color 颜色:Color(r,g,b,a)具体参见:Color

返回值

  • : StyleString

setFontColorForRange

给部分内容设置颜色

@note 如果此方法与fontColor同时使用,应先调用fontColor方法

参数

  • fontColor : Color 背景颜色:Color(r,g,b,a)具体参见:Color
  • index : number 指定范围的起始位置索引, 从1开始
  • length : number 指定范围的字符长度

返回值

  • : StyleString

backgroundColor

背景颜色

参数

  • color : Color 背景颜色:Color(r,g,b,a)具体参见:Color

返回值

  • : StyleString

setBackgroundColorForRange

给部分内容设置背景颜色

@note 如果此方法与backgroundColor同时使用,应先调用backgroundColor方法

参数

  • color : Color 背景颜色:Color(r,g,b,a)具体参见:Color
  • index : number 指定范围的起始位置索引, 从1开始
  • length : number 指定范围的字符长度

返回值

  • : StyleString

underline

设置下划线

@note

参数

  • style : UnderlineStyle 下划线样式UnderlineStyle

返回值

  • : StyleString

setUnderlineForRange

给部分内容设置下划线

@note 如果此方法与underline同时使用,应先调用underline方法

参数

  • style : UnderlineStyle 下划线样式UnderlineStyle
  • index : number 指定范围的起始位置索引, 从1开始
  • length : number 指定范围的字符长度

返回值

  • : StyleString

showAsImage

以Image的形式展示,常用于图文混排

以Image的形式展示,前提是当前内容为图片网络路径或本地路径,且以图片形式展示后,背景色,下划线,字体等样式无法设置

@note 使用场景:用于向字符串中间插入图片进行展示

参数

  • size : Size 图片大小

返回值

  • 返回图片是否设置成功 : boolean

append

尾部追加StyleString

参数

  • styleString : StyleString 追加的富文本字符串

返回值

  • : StyleString

calculateSize

计算显示该内容需要的最小尺寸

@note 此方法在iOS上算的不准,可能导致iOS上 用来设置label宽度时,文字被截断。 iOS上建议使用StringUtil:sizeWithContentFontSize方法; 另外,如果是用于 label 布局,推荐使用线性布局。

参数

  • maxWidth : number 限定显示当前内容的最大宽度

返回值

  • 返回显示当前内容所需要的最小尺寸 : Size Size)

setText

设置文本内容

参数

  • content : string 文本内容

返回值

  • : StyleString
Prev
Color 类