我尝试将文本光标垂直居中于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;

我尝试在最后一行执行UIControlContentVerticalAlignmentCenter,但仍然无法正常工作。

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



有办法解决吗?

最佳答案

使用textContainerInsetUITextView属性(适用于iOS 7.0和更高版本)。

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

试玩这些值,直到它适合您的需求。

10-08 05:52