如何在用户点击ios中的“更多”button时扩展UITextview

有UITextview应用程序显示给定数量的行,当用户点击更多的扩展和其余显示,如何添加越来越less的button。请给我任何想法。 我是编程新手。我知道如何编写UITextview.But的代码,但是我不知道如何编写UITextview.Thanks或多或less的button的代码。

在这里输入图像说明

1.根据文本和字体检查UItextView大小:

// return the size for UITextView for both IOS7 and IOS6 -(CGSize) getSizeWithMaxLabelSize:(CGSize) maxLabelSize forTextViewWithText:(NSString *) text { CGSize expectedLabelSize; CGSize maximumLabelSize = maxLabelSize; if (SYSTEM_VERSION_GREATER_THAN(@"6.2")) { NSDictionary *stringAttributes = [NSDictionary dictionaryWithObject:[UIFont fontWithName:@"Arial" size:EPCommentViewFontSize] forKey: NSFontAttributeName]; CGRect rect =[text boundingRectWithSize:maximumLabelSize options:NSStringDrawingUsesLineFragmentOrigin attributes:stringAttributes context:nil]; expectedLabelSize = rect.size; expectedLabelSize.height = ceilf(expectedLabelSize.height); expectedLabelSize.width = ceilf(expectedLabelSize.width); } else { expectedLabelSize = [text sizeWithFont:[UIFont fontWithName:@"Arial" size:EPCommentViewFontSize] constrainedToSize:maximumLabelSize lineBreakMode:NSLineBreakByWordWrapping]; } return expectedLabelSize; } 

frame.size.height UITextView frame.size.height

 CGRect frame = _textView.frame; frame.size.height = [self getSizeWithMaxLabelSize:CGSizeMake(_textView.frame.size.height, NSIntegerMax) forTextViewWithText:_textView.text].height; _textView.frame = frame; 

3.更改子视图布局

 // this will work only if you textview is on the top of other views. [UIView animateWithDuration:0.25 animations:^{ for (UIView *subview in self.view.subviews) subview.transform = CGAffineTransformMakeTranslation(0, _textView.frame.size.height); }]; 

应该是这样。