Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to vertically center the cursor in a UITextView

I try to vertically center my text cursor in a UITextView.

// creating the inputText
[inputTextView removeFromSuperview];
inputTextView = [[UITextView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(searchIconsButton.frame) + 3 , 0, buttomView.frame.size.width * 0.78 , buttomView.frame.size.height *0.80)];
inputTextView.layer.borderColor = [UIColor lightGrayColor].CGColor;
inputTextView.layer.borderWidth = 0.6;
inputTextView.center = CGPointMake(inputTextView.center.x, buttomView.frame.size.height / 2);
inputTextView.autocorrectionType = UITextAutocorrectionTypeNo;
[inputTextView.layer setCornerRadius:6];
[inputTextView setTintColor:[UIColor blackColor]]; // set the cursor color to black
inputTextView.textAlignment = UIControlContentVerticalAlignmentCenter;

I try in last line to do UIControlContentVerticalAlignmentCenter but it still do not work .

You can see that the cursor hides into the Textview.

There is a way to solve it?

like image 946
Roei Nadam Avatar asked Dec 08 '14 11:12

Roei Nadam


1 Answers

Use the textContainerInset property of UITextView, available iOS 7.0 and later.

inputTextView.textContainerInset = UIEdgeInsetsMake(-2,0,0,0); // Move cursor up 2

Play around with the values until it fits your needs.

like image 155
Eric Amorde Avatar answered Nov 08 '22 11:11

Eric Amorde