UITextView 末尾的额外空间 [英] Extra space at the end of UITextView
问题描述
我在 UITextView
中添加了文本并理解边界,我用青色为我的 UITextView
着色.
I added text in UITextView
and to understand the boundaries I colored my UITextView
with cyan color.
在 google.com 之后,我想删除一些额外的空间.
After google.com there is some extra space which I want to remove.
- (void)viewDidLoad {
[super viewDidLoad];
NSString *desc = [self htmlAfterReplacingTagsAndAddingStyle];
_descriptionTextView.attributedText = [[NSAttributedString alloc] initWithData: [desc dataUsingEncoding:NSUTF8StringEncoding] options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
_descriptionTextView.linkTextAttributes = @{ NSForegroundColorAttributeName: [UIColor blueColor], NSUnderlineStyleAttributeName: [NSNumber numberWithInt:NSUnderlineStyleSingle] };
_descriptionTextView.dataDetectorTypes = UIDataDetectorTypeLink;
_descriptionTextView.scrollEnabled = NO;
[self setTextViewHeight];
}
setTextViewHeight
- (void)setTextViewHeight {
UIFont *font = [UIFont fontWithName:@"OpenSans" size:14.0];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, _descriptionContainer.frame.size.width, CGFLOAT_MAX)];
label.numberOfLines = 0;
label.lineBreakMode = NSLineBreakByWordWrapping;
label.font = font;
NSString *desc = [self htmlAfterReplacingTagsAndAddingStyle];
label.attributedText = [[NSAttributedString alloc] initWithData: [desc dataUsingEncoding:NSUTF8StringEncoding] options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
[label sizeToFit];
_descriptionTextView.backgroundColor = UIColor.cyanColor;
[_descriptionTextView setContentInset:UIEdgeInsetsMake(0, 0, -80, 0)];
_descriptionContainerHeight.constant = label.frame.size.height;
}
我阅读了有关设置内容插入的内容,但这没有帮助.更改 -80 的值没有任何影响.
I read about setting content inset but that is not helpful. Changing the value of -80 doesn't have any impact.
如果有一些指针可以帮助我删除 uitextView 底部的额外空间,我将不胜感激.
I would appreciate some pointers which can help me remove the extra space present at the bottom of uitextView.
推荐答案
使用
[_descriptionTextView setTextContainerInset:UIEdgeInsetsMake(0, 0, 0, 0)];
可以在UITextView
类参考中阅读
textContainerInset 属性 文本容器布局的插入文本视图内容区域内的区域.
textContainerInset Property The inset of the text container's layout area within the text view's content area.
声明
目标-C@property(nonatomic,assign) UIEdgeInsets文本容器插入
OBJECTIVE-C @property(nonatomic, assign) UIEdgeInsets textContainerInset
讨论
此属性提供文本边距文本布局在文本视图中.默认情况下这个属性的值是 (8, 0, 8, 0).
This property provides text margins for text laid out in the text view. By default the value of this property is (8, 0, 8, 0).
希望能帮到你
这篇关于UITextView 末尾的额外空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!