我设置了一个奇怪的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];
答案 0 :(得分:3)
我设法解决了这个问题,最后我只需要像这样定义textview,并使用固定的宽度:
> UITextView * messageTextView = [[UITextView alloc]
> initWithFrame:CGRectMake(46.0f, 0.0f, 240.0f, messageSize.height +
> 25)];