简体   繁体   中英

how to insert a UIButton in UITextView at any cursor position in UITextView

in my application i have a UITextView . In that UITextView user enter text,when user click UIButton (already in Toolbar) , it need to insert a UIButton at cursors current position. How can i get the cursor's X and Y co-ordianates. programmatically?

my code is below UIButton (already in Toolbar)

-(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];
}

here i need to replace the value

myButton.frame = CGRectMake(X, Y, 10, 10);

is it possible to get the X and Y values of cursor.?

您可以使用caretRectForPosition方法来查找光标的点,也许然后您可以前进

CGPoint cursorPosition = [textview caretRectForPosition:textview.selectedTextRange.start].origin;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM