我在UITextView
中添加了文本,并了解了用青色将我的UITextView
上色的边界。UITextView结尾的额外空间
后google.com有,我想删除一些额外的空间。
- (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的值不会有任何影响。
我将不胜感激一些指针,可以帮助我删除uitextView底部的额外空间。
同意。我认为OP的测量字符串高度的方法要么不正确,要么至少是浪费。 – danh
@AsthaGupta我的答案解决了你的问题? –
嗨Reinier - 谢谢你的答案。但它在某些情况下有效,并非全部。如果我的字符串没有换行符,那么它就像一个魅力。但是,如果我的字符串有换行符,那么我仍然面临上面发布的问题。我会upvote你的答案,但不能接受它作为解决方案:) –