在 UITextView Objective-C 内的文本末尾添加更多按钮? [英] Add more button at the end of text inside UITextView Objective-C?

查看:27
本文介绍了在 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 中使用按钮的矩形作为
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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆