weex 富文本_支持圆角、渐变、边框等样式的WEEX富文本组件

介绍

本仓库是iOS端的weex富文本组件。本质上是一个UITextView,用于将HTML字符串解析成NSAttributedString。

但是,并不是所有HTML样式都能被解析出来,比如圆角、渐变、边框等。

本组件对这些特殊样式也一样做了支持,并且支持自定义超链接颜色、文字行数获取等扩展功能。

Cocoapods

pod 'KSWXRichTextComponent'

效果演示

example.png?raw=true

如何使用

1.原生中注册组件

[WXSDKEngine registerComponent:@"rich-text" withClass:[KSWXRichTextComponent class]];

2.前端中使用组件

.rich {

color: red;

}

外部样式(class)

color: ;

fontFamily: ;

fontSize: ;

textAlign: ;

lineHeight: ;

paddingLeft: ;

paddingRight: ;

paddingTop: ;

paddingBottom: ;

letterSpacing: ;

textOverflow: ; // only ellipsis

lines: ;

内部样式(style)

支持所有样式,但是并不是都会被解析出来,比如圆角相关样式

圆角相关样式(style)

style中带border样式的会被解析成图片附件(NSTextAttachment)替换原来的富文本

/*自带以下样式,修改无效*/

display: inline-block;

border-style: solid;

white-space: nowrap;

overflow: hidden;

/*渐变色支持四个方向*/

background-image: linear-gradient(to {where}, {color}, {color}, ...);

/*只支持ellipsis*/

text-overflow: ellipsis;

/*只支持left、right、center*/

text-align: ;

margin: ;

margin-top: ;

margin-bottom: ;

margin-left: ;

margin-right: ;

padding: ;

padding-top: ;

padding-bottom: ;

padding-left: ;

padding-right: ;

font-size: ;

font-family: ;

color: ;

border-radius: ;

background-color: ;

height ;

width: ;

line-height: ;

border-width: ;

border-color: ;

DOM方法

1.获取行数

$refs.richtext.getTextLineInfo((res) => {

const arg = JSON.parse(res)

res.maxLine // 最大行数

res.realLine // 实际行数

})

超链接监听

[KSWXRichTextComponent observeLinkClick:^(WXSDKInstance *weexInstance, NSURL *URL) {

if ([URL.scheme isEqualToString:@"somescheme"]) {

// do some thing

}

}];

超链接样式自定义

[KSWXRichTextComponent addDefaultStyles:@{KSWXRichTextLinkTextColorKey: [UIColor orangeColor],

KSWXRichTextLinkUnderlineColorKey: [UIColor orangeColor]

}];

LICENSE

MIT

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值