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 high123456
我们来不来,整一个吧
那算是东风路按劳动法就开始灾难性的服你
is in Verdana and red'}
},
mounted: function () {
this.aaa()
},
methods: {
aaa: function () {
}
}
}
组件在iOS工程中创建,继承自WXComponent
.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]];