Why is UITextView contentInset/padding different on simulator vs device?
I'm debugging a strange text wrapping problem on my device that I have tracked down to some kind of modification in the UITextView contentInset value starting in XCode 4.
Here is the sample code I am using to showcase this bug:
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];
Attached are two screenshots running code on the iOS 5 simulator and on my iPhone 4.
Here is the iPhone 4 running iOS5:
Here is the simulator running iOS5.0:
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:
CGRect textViewFrame = CGRectMake(xOffset, yOffset, messageDimensions.width+16, messageDimensions.height+16);
To have a padding of +17 not +16.
Can anyone tell me if this is a known bug, and if the UITextView padding amount is a constant value somewhere in UIKit to which I can refer instead of hard-coding it?