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

标签 ios objective-c parse-platform uibutton uitextview

我正在尝试执行类似于此链接 http://www.oracle.com/webfolder/ux/mobile/pattern/img/expand-collpase-description.png 中的操作

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

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

从 PFQuery 加载数据后,我正在 UITextView 内设置按钮的框架

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 内添加更多按钮?此外,我还创建了一个约束,以在单击“更多”按钮时增加其高度,但我无法将约束的高度增加到超过某个阈值大小。

最佳答案

我也在做同样的事情。只需将按钮添加到textView.superView即可,因为textView是scrollView。在textView中使用按钮的矩形作为
textView.textContainer.exclusionPaths = [UIBezierPath(矩形:矩形)]

我终于做到了。最重要的是 rect 必须包含textView.frame 中。

关于ios - 在 UITextView Objective-C 中的文本末尾添加更多按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33088565/

相关文章:

objective-c - XCode 中的全局字符串问题

ios - 选择 searchBar 时在 UISearchController 中预加载数据

ios - 解析,无法从 iOS 应用程序中删除 PFObject?

ios - 单击主视图 Controller 中的按钮以将录制的视频保存在容器 View 中?

ios - UIView 中的 UITableView 未触发 didSelectRowAtIndexPath

objective-c - 为什么我看到一个 ARC 问题说我确实声明了一个带有特定选择器的方法?

javascript - 获取解析 session ID

java - 将类类型传递给方法

ios - URLWithString:即使使用正确的URL构造,也返回nil

iphone - 将对象转换为 plist 文件,然后转换为数据