在我的ios应用中 我正在渲染HTML标签 使用
DTAttributedTextView
这是编码结构的其余部分
//create the custom label to get positions
UILabel *customLabel = [[UILabel alloc]initWithFrame:CGRectMake(lblContent.frame.origin.x, lblContent.frame.origin.y,lblContent.frame.size.width,lblContent.frame.size.height)];
customLabel.text = _artistDetail.strContent;
customLabel.numberOfLines = 0;
[customLabel sizeToFit];
[lblContent removeFromSuperview];
CGRect frame = CGRectMake(customLabel.frame.origin.x, customLabel.frame.origin.y,customLabel.frame.size.width,500);
NSString *htmlText = HTML_DIV_TAG;
htmlText = [htmlText stringByAppendingFormat:@"%@%@",_artistDetail.strContent,@"</div>"];
htmlText = [htmlText stringByReplacingOccurrencesOfString:@"''" withString:@"'"];
NSData *data = [htmlText dataUsingEncoding:NSUTF8StringEncoding];
NSAttributedString *string = [[NSAttributedString alloc] initWithHTML:data options:nil documentAttributes:NULL];
[DTAttributedTextContentView setLayerClass:[CATiledLayer class]];
DTAttributedTextView *_textView = [[DTAttributedTextView alloc] initWithFrame:frame];
_textView.textDelegate = self;
_textView.attributedString = string;
[_textView sizeToFit];
_textView.autoresizesSubviews = YES;
[self.contentView addSubview:_textView];
现在我想根据内容高度增加标签 是以任何方式做到这一点 感谢
答案 0 :(得分:0)
你有没有试过像:
[DTAttributedTextContentView setLayerClass:[CATiledLayer class]];
DTAttributedTextView *_textView = [[DTAttributedTextView alloc] initWithFrame:frame];
_textView.textDelegate = self;
_textView.attributedString = string;
CGRect frame = _textView.frame;
CGSize size = _textView.contentSize;
frame.size.height = size.height;
_textView.frame = frame;
[self.contentView addSubview:_textView];