在文本视图中添加按钮 [英] add button inside a text view

查看:100
本文介绍了在文本视图中添加按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本视图,其中我想要一个相机按钮。在我的应用程序中,我希望用户键入一些文本,然后他/她想要附加照片或视频。我已经完成了,但我想在文本视图中的相机按钮。当我尝试添加按钮作为子视图按钮滚动文本但我想要按钮固定而另一个问题是文本进入按钮区域不可见所以我希望光标不会进入按钮所覆盖的区域。

I have a text view in which i want a button for camera. In my application i want that user type some text then he/she want to attach a photo or video. I have done that but the camera button i want inside the text view. when i try to add a button as subview that button scrolled with the text but i want button fixed and another problem is that the text comes in button area not visible so i want that the cursor will not go in that area which is covered by button.

UIButton *myButton  =   [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame      =   CGRectMake(0, 0, 50.0, 30.0);

[editButton addTarget:self action:@selector(editPressed:)forControlEvents:UIControlEventTouchUpInside];
myButton.backgroundColor=[UIColor blueColor];
[txtView addSubview:myButton];


推荐答案

-


  • 试试这个。它一定会为你工作并解决你的问题

  • Try this .It will definitely work for you and will solve your issue

在ViewDidLoad方法中写下以下代码。

Write below code in ViewDidLoad Method.


-(void)textResizeForButton{

    CGRect buttonFrame = self.button.frame;
    UIBezierPath *exclusivePath = [UIBezierPath bezierPathWithRect:buttonFrame];
    self.textView.textContainer.exclusionPaths = @[exclusivePath];

}


这篇关于在文本视图中添加按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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