UITextView * textView = [[UITextView alloc] init];
1、设置内边距
// 设置上、左、下
textView.textContainerInset = UIEdgeInsetsMake(0, 15, 0, 15);// 设置底部边距
textView.contentInset = UIEdgeInsetsZero;
2、左侧顶格显示/输入内容
textView.textContainer.lineFragmentPadding = 0;
3、 防止拼音打字时抖动
textView.layoutManager.allowsNonContiguousLayout = NO;
4、编辑状态下的行间距
textView.typingAttributes = @{NSFontAttributeName : font, NSParagraphStyleAttributeName : style};
5、修改行间距会出现光标size变长的问题
通过继承 UITextView,重写 caretRectForPosition:
- (CGRect)caretRectForPosition:(UITextPosition *)position {
CGRect originalRect = [super caretRectForPosition:position];
originalRect.size.height = self.font.lineHeight + 2;
return originalRect;
}