如何将光标垂直居中在UITextView中

Roe*_*dam 3 objective-c textview

我尝试将文本光标垂直居中在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;
Run Code Online (Sandbox Code Playgroud)

我尝试在最后一行做UIControlContentVerticalAlignmentCenter,但它仍然无法正常工作.

您可以看到光标隐藏在Textview中.

有办法解决吗?

Eri*_*rde 5

使用可用的iOS 7.0及更高版本的textContainerInset属性UITextView.

inputTextView.textContainerInset = UIEdgeInsetsMake(-2,0,0,0); // Move cursor up 2
Run Code Online (Sandbox Code Playgroud)

尽情享受价值观,直至满足您的需求.