Skip to content

Instantly share code, notes, and snippets.

@lqik2004
Created July 21, 2012 14:30
Show Gist options
  • Select an option

  • Save lqik2004/3155956 to your computer and use it in GitHub Desktop.

Select an option

Save lqik2004/3155956 to your computer and use it in GitHub Desktop.
设置UITextView Padding
//设置padding
-(void) padding{
//padding大小(top,left,bottom,right)
UIEdgeInsets padding = UIEdgeInsetsMake(0, 15, 0, 15);
_textView.contentInset = padding;
CGRect frame = _textView.frame;
// must change frame before bounds because the text wrap is reformatted based on frame, don't include the top and bottom insets
CGRect insetFrame = UIEdgeInsetsInsetRect(frame, UIEdgeInsetsMake(0, padding.left, 0, padding.right));
// offset frame back to original x
CGFloat offsetX = frame.origin.x - (insetFrame.origin.x - ( padding.left + padding.right ) / 2);
insetFrame = CGRectApplyAffineTransform(insetFrame, CGAffineTransformMakeTranslation(offsetX, 0));
_textView.frame = insetFrame;
_textView.bounds = UIEdgeInsetsInsetRect(_textView.bounds, UIEdgeInsetsMake(0, -padding.left, 0, -padding.right));
[_textView scrollRectToVisible:CGRectMake(0,0,1,1) animated:NO];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment