在UITextView Objective-C中的文本末尾添加更多按钮? [英] Add more button at the end of text inside UITextView Objective-C?
问题描述
我正在尝试做类似于此链接中的内容 http://www.oracle.com/webfolder/ux/mobile/pattern/img/expand-collpase-description.png
I am trying to do something similar to the one in this link http://www.oracle.com/webfolder/ux/mobile/pattern/img/expand-collpase-description.png
单击更多按钮时,在UITextView中展开内容。我在viewDidLoad中创建按钮,如下所示
Expanding the content inside a UITextView when clicking the button 'more'. I am creating the button in my viewDidLoad like the below
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"more" forState:UIControlStateNormal];
[self.detailPriceView addSubview:button];
我在从PFQuery加载数据后设置UITextView内的按钮框架
I am setting the frame of the button inside the UITextView after loading the data from PFQuery
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];
}
}];
如何在文本末尾的UITextView中添加更多按钮?此外,我创建了一个约束,以便在单击更多按钮时增加其高度,但我无法将约束的高度增加到超过某个阈值大小。
How to add more button inside UITextView at the end of the text ? Also i created a constraint to increase it's height when the more button is clicked, but i'm unable to increase the constraint's height beyond some threshold size.
推荐答案
我正在做同样的事情。只需将按钮添加到textView.superView,因为textView是scrollView。在textView中使用button的rect作为
textView.textContainer.exclusionPaths = [UIBezierPath(rect:rect)]
I'm doing the same thing. Just add the button to textView.superView, because textView is scrollView. Use button's rect in textView as
textView.textContainer.exclusionPaths = [UIBezierPath(rect: rect)]
最后,我做到了。最重要的是 rect
必须包含 textView.frame
。
At last, I did it. Most important thing is rect
must be included in textView.frame
.
这篇关于在UITextView Objective-C中的文本末尾添加更多按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!