1

我设置了一个UITextView奇怪的行为。如果我将它的内容设置为很长text,它会在边界处正确地打破它,但是如果内容是单行的,它会在最后一个单词之前自动打破它,即使它适合一行。它创造了最少的线条。

我在网上找不到这个问题,所以我不得不问。

这里是设置UITextView

Message * displayedMessage = [messages objectAtIndex:indexPath.row];
UIFont * messageFont = [UIFont fontWithName:@"Helvetica" size:13];
CGSize messageSize = [displayedMessage.content sizeWithFont:messageFont constrainedToSize:CGSizeMake(240.f, 3000.f) lineBreakMode:UILineBreakModeWordWrap];
UITextView * messageTextView = [[UITextView alloc] initWithFrame:CGRectMake(46.f, 0.f, messageSize.width, messageSize.height + 25)];

messageTextView.backgroundColor = [UIColor clearColor];
messageTextView.font = messageFont;
messageTextView.editable = NO;
messageTextView.scrollEnabled = NO;
messageTextView.contentInset = UIEdgeInsetsZero;    
messageTextView.textColor = [UIColor blackColor];
[messageTextView setDataDetectorTypes:UIDataDetectorTypeAll];
messageTextView.text = displayedMessage.content;
[cell addSubview:messageTextView];
4

1 回答 1

3

我最终设法解决了它,我只需要像这样定义文本视图,宽度固定:

> UITextView * messageTextView = [[UITextView alloc]
> initWithFrame:CGRectMake(46.0f, 0.0f, 240.0f, messageSize.height +
> 25)];
于 2012-05-21T12:20:27.720 回答