TextView中的光标最初太小了?

时间:2018-05-30 03:24:14

标签: xcode storyboard uistoryboard uitextviewdelegate

我有一个iOS应用程序。当用户单击文本视图时,光标最初非常小。这就是它的样子:

enter image description here

一旦用户开始输入,光标就会改变大小并变得更大。这就是它的样子:

enter image description here

如您所见,第二张图像中的光标大于第一张图像中的光标。如何使初始光标变大?我希望它与用户开始输入时显示的光标大小相同。

这是我的代码:

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UITextViewDelegate {

    @IBOutlet weak var userMessageTextView: UITextView!

    override func viewDidLoad() {
        super.viewDidLoad()

        self.userMessageTextView.delegate = self

        //Used to make the border of the TextView look the same as the border of a TextField
        userMessageTextView.layer.borderColor = UIColor(red: 0.9, green: 0.9, blue: 0.9, alpha: 1.0).cgColor
        userMessageTextView.layer.borderWidth = 1.0
        userMessageTextView.layer.cornerRadius = 5   
    }

    func textViewDidBeginEditing(_ textView: UITextView) {
        //Used to Make the Cursor appear somewhat centered in the TextView; Without this, the bottom of the cursor is lined up with the bottom edge of the TextView, so the cursor is not centered within the textView
        userMessageTextView.contentOffset.y = 4.0
    }
}

0 个答案:

没有答案