Note that there are some explanatory texts on larger screens.

plurals
  1. POUITextView wraps text when built with iOS 7 SDK
    primarykey
    data
    text
    <p>I have a <code>UITextView</code> inside a <code>UIScrollView</code> that worked perfectly fine on <code>iOS 6</code> built from <code>xcode 4.x</code>, however now building with <code>xcode 5</code> it doesn't work properly, even on <code>iOS 6</code>.</p> <p>The problem is the text wraps with the screen width even though the <code>UITextView</code> and <code>UIScrollView</code> have large widths. I use this code to work out the new width and height of the <code>UITextView</code>, and even though the textview scrolls left/right the text is wrapped as if the width is only the width of the screen.</p> <p>Thanks</p> <pre><code>self.responceTextView.text = [NSString stringWithFormat:@"%@%@",_responceTextView.text,responce]; [self textViewDidChange:self.responceTextView]; - (void)textViewDidChange:(UITextView *)textView { // Recalculate size of text field CGSize maxSize = CGSizeMake(MAXFLOAT, MAXFLOAT); CGSize reqSize = [textView.text sizeWithFont:[UIFont fontWithName:@"Courier" size:12] constrainedToSize:maxSize lineBreakMode:NSLineBreakByClipping]; self.responceTextView.frame = CGRectMake(0, 0, reqSize.width+16, reqSize.height+16); // Resize scroll view if needs to be smaller so text stays at top of screen CGFloat maxScrollHeight = maxScrollViewSize.size.height; if (self.responceTextView.frame.size.height &lt; maxScrollHeight) { self.responceScrollView.frame = CGRectMake(self.responceScrollView.frame.origin.x, self.responceScrollView.frame.origin.y, self.responceScrollView.frame.size.width, self.responceTextView.frame.size.height); } else { self.responceScrollView.frame = maxScrollViewSize; } // Set content size self.responceScrollView.contentSize = CGSizeMake(self.responceTextView.frame.size.width, self.responceTextView.frame.size.height); [self scrollToCursor]; } </code></pre> <p>EDIT ----</p> <p>Ok, so it seems <code>sizeWithFont</code> is deprecated in iOS 7. Strange how I get no compiler warning. It still doesn't make sense that it doesn't work on iOS 6 (or is it completely removed when built with iOS 7 SDK?)</p> <p>I have tried these 2 alternatives, but get exactly the same size back from all.</p> <pre><code>NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: [UIFont fontWithName:@"Courier" size:12], NSFontAttributeName, nil]; CGRect rect = [textView.text boundingRectWithSize:maxSize options:NSLineBreakByClipping | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attributes context:nil]; </code></pre> <p>returns: <code>{{0, 0}, {439.27148, 168}}</code></p> <pre><code>CGSize rect2 = [textView.text sizeWithAttributes:attributes]; </code></pre> <p>returns: <code>{439.27148, 168}</code></p> <p>And the original above returns <code>{439.27148, 168}</code></p> <p>They should all return a wider view. </p> <p>EDIT 2 ---- It seems from above that the returned frame is correct (439 wide) however it's the text that is still being word wrapped inside the textview.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload