0

我需要显示包含 HTML 标签等的文本,并且 TTStyledTextLabel 符合要求……但它不会滚动。

我在 UITextView 中放置了一个,但这拒绝滚动?如果我直接在 UITextView 中输入文本,它会滚动正常,但我会看到所有未格式化的 HTML。

有没有办法将 TTStyledTextLabel 设置为滚动?

谢谢

4

2 回答 2

1

尝试将TTStyledTextLabel.UIScrollView

或者,您可以考虑UIWebView直接使用 a 。

于 2011-06-13T21:09:57.987 回答
0

I finally got a suitable work around...

CGSize constraintSize;

CGSize stringSize;

// make an overly big size allowance

constraintSize.width = 300;

constraintSize.height = 2000;

NSString *s = @"this can be text as long or as short as required...;

UIFont *f = [UIFont fontWithName:@"Arial" size:14];

stringSize =[s sizeWithFont:f constrainedToSize: constraintSize lineBreakMode: UILineBreakModeWordWrap];

// create a label to accomodate the text

UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(14, 2, stringSize.width, stringSize.height)];

l.text = s;

[l setNumberOfLines:0];

[l sizeToFit];

// now create a TTStyledTextLabel to match the size we just obtained above

TTStyledTextLabel *tl = [[TTStyledTextLabel alloc] initWithFrame:[l frame]];

// set the text making use of links etc

tl.text = [TTStyledText textFromXHTML:l.text lineBreaks:YES URLs:YES];

[tl setBackgroundColor:[UIColor clearColor]];

tl.textColor = [UIColor whiteColor];

UIScrollView *sv = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 185, 320, 300)];

// adjust scrollview content size to accomodate the TTStyledTextLabel

[sv setContentSize:CGSizeMake(tl.frame.size.width, tl.frame.size.height)];

[sv addSubview:tl];

[self.view addSubview:sv];

Now I can have an auto sizing TTStyledTextLabel that scrolls ;-)

于 2011-06-22T13:17:30.490 回答