Created
July 21, 2012 14:30
-
-
Save lqik2004/3155956 to your computer and use it in GitHub Desktop.
设置UITextView Padding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //设置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