我有一个文本视图,我想要一个用于相机的按钮。在我的应用程序中,我希望用户输入一些文本,然后他/她想要附加照片或视频。我已经这样做了,但是我想要在文本视图中的相机按钮。当我尝试添加一个按钮作为子视图时,该按钮与文本一起滚动,但我想要修复按钮,另一个问题是文本进入按钮区域不可见,所以我希望光标不会进入按钮覆盖的区域.
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];
Run Code Online (Sandbox Code Playgroud)
—— 
试试这个。它肯定会为你工作,并会解决你的问题
在 ViewDidLoad 方法中编写以下代码。
.
Run Code Online (Sandbox Code Playgroud)-(void)textResizeForButton{ CGRect buttonFrame = self.button.frame; UIBezierPath *exclusivePath = [UIBezierPath bezierPathWithRect:buttonFrame]; self.textView.textContainer.exclusionPaths = @[exclusivePath]; }
| 归档时间: |
|
| 查看次数: |
3049 次 |
| 最近记录: |