Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is UITextView contentInset/padding different on simulator vs device?
    text
    copied!<p>I'm debugging a strange text wrapping problem on my device that I have tracked down to some kind of modification in the <code>UITextView</code> contentInset value starting in XCode 4. </p> <p>Here is the sample code I am using to showcase this bug:</p> <pre><code>NSString *message = @"How are you doing?"; CGSize messageDimensions = [message sizeWithFont:[UIFont systemFontOfSize:15.0] constrainedToSize:CGSizeMake(self.view.frame.size.width,9999) lineBreakMode:UILineBreakModeWordWrap]; CGFloat xOffset = 20; CGFloat yOffset = 20; CGRect textViewFrame = CGRectMake(xOffset, yOffset, messageDimensions.width+16, messageDimensions.height+16); self.textView = [[[UITextView alloc] initWithFrame:textViewFrame] autorelease]; self.textView.font = [UIFont systemFontOfSize:15.0]; self.textView.text = message; self.textView.editable = NO; [self.view addSubview:self.textView]; </code></pre> <p>Attached are two screenshots running code on the iOS 5 simulator and on my iPhone 4. </p> <p>Here is the iPhone 4 running iOS5: </p> <p><img src="https://i.stack.imgur.com/EBKxW.png" alt="device"></p> <p>Here is the simulator running iOS5.0:</p> <p><img src="https://i.stack.imgur.com/O1Yxm.png" alt="simulator"></p> <p>As you can see, it is wrapping in one but not the other. In order to prevent wrapping on my iOS4 device I have to change this line:</p> <pre><code>CGRect textViewFrame = CGRectMake(xOffset, yOffset, messageDimensions.width+16, messageDimensions.height+16); </code></pre> <p>To have a padding of +17 not +16. </p> <p>Can anyone tell me if this is a known bug, and if the <code>UITextView</code> padding amount is a constant value somewhere in UIKit to which I can refer instead of hard-coding it? </p> <p>Thanks!</p>
 

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