在我的应用程序中,我有一个UITextView
。在UITextView
用户输入文字时,当用户点击 UIButton(已在工具栏中)时,需要在游标当前位置插入UIButton
。我如何获得光标的X和Y协调。编程?
我的代码位于 UIButton(已在工具栏中)
之下-(void)inserButton
{
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
myButton.frame = CGRectMake(30, 5, 10, 10);
UIImage *Chkimg = [UIImage imageNamed:@"unchk.png"];
[myButton setBackgroundImage:Chkimg forState:UIControlStateNormal];
[note addSubview:myButton];
}
这里我需要替换值
myButton.frame = CGRectMake(X, Y, 10, 10);
是否可以获取光标的X和Y值。?
答案 0 :(得分:1)
您可以使用caretRectForPosition
方法查找光标点,然后您可以前进
CGPoint cursorPosition = [textview caretRectForPosition:textview.selectedTextRange.start].origin;