0

在我的 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];

现在我想根据内容高度增加标签是否有任何方法可以做到谢谢

4

1 回答 1

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];
于 2012-11-28T17:15:34.337 回答