html 自定义标签 ios,自定义IOS简单富文本组件(显示html标签内容)

The environment is ready,lll拉萨京津冀的方式的经适房的副驾驶的福建省昂科拉计算机设计师的方式!

export default {

name: 'App',

data () {

return {

logo: 'https://gw.alicdn.com/tfs/TB1yopEdgoQMeJjy1XaXXcSsFXa-640-302.png',

t: '

这里要厕所个富文本

This text is in Times and greenThis text is 50 pixels highcover123456

我们来不来,整一个吧

那算是东风路按劳动法就开始灾难性的服你

is in Verdana and red'

}

},

mounted: function () {

this.aaa()

},

methods: {

aaa: function () {

}

}

}

组件在iOS工程中创建,继承自WXComponent

0a6f0bd2cb14?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

.m文件

#import "RFRichTextComponent.h"

#import

@implementationRFRichTextComponent{

NSString*_text;

CGFloat_fWidth;

CGFloat_fHeight;

}

- (id)initWithRef:(NSString*)ref type:(NSString*)type styles:(NSDictionary*)styles attributes:(NSDictionary*)attributes events:(NSArray*)events weexInstance:(WXSDKInstance*)weexInstance

{

if(self= [superinitWithRef:reftype:typestyles:stylesattributes:attributesevents:eventsweexInstance:weexInstance]) {

[selffillAttributes:attributes];

[selffillStyles:styles];

}

return self;

}

- (UIView*)loadView

{

UIView*lbl = [UIViewnew];

lbl.userInteractionEnabled = YES;

returnlbl;

}

- (void)viewDidLoad

{

[selfrepaint];

}

- (void)fillStyles:(NSDictionary*)styles{

idw = styles[@"width"];

if(w) {

_fWidth= [wfloatValue];

}

idh = styles[@"height"];

if(h) {

_fHeight= [hfloatValue];

}

}

- (void)fillAttributes:(NSDictionary*)attributes

{

idtext = attributes[@"text"];

if(text) {

_text= [WXConvertNSString:text];

[self setNeedsLayout];

}

}

- (void)repaint{

for(UIView *sub in self.view.subviews){

[subremoveFromSuperview];

}

UILabel *label = [[UILabel alloc] initWithFrame:self.view.bounds];  //CGRectMake(0, 0, _fWidth, _fHeight)

label.numberOfLines=0;

[self.viewaddSubview:label];

//    NSString *content = @"

This text is 50 pixels high";

NSData *data = [_text dataUsingEncoding:NSUnicodeStringEncoding];

NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};

NSAttributedString *html = [[NSAttributedString alloc]initWithData:data

options:options

documentAttributes:nil

error:nil];

label.attributedText= html;

NSLog(@"====前:%.1f,%.1f,%.1f,%.1f",label.frame.origin.x,label.frame.origin.y, label.frame.size.width, label.frame.size.height);

[labelsizeToFit];

NSLog(@"====后:%.1f,%.1f,%.1f,%.1f",label.frame.origin.x,label.frame.origin.y, label.frame.size.width, label.frame.size.height);

_fWidth= label.frame.size.width;

_fHeight= label.frame.size.height;

}

- (void)updateAttributes:(NSDictionary*)attributes{

[superupdateAttributes:attributes];

}

注册组件

[WXSDKEngine registerComponent:@"textcomponent" withClass:[RFRichTextComponent class]];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值