Ответ 1
Наконец я нашел решение, которое решило мою проблему.
Изменение высоты курсора возможно путем создания подкласса UITextView
последующим переопределением функции caretRectForPosition:position
. Например:
- (CGRect)caretRectForPosition:(UITextPosition *)position {
CGRect originalRect = [super caretRectForPosition:position];
originalRect.size.height = 18.0;
return originalRect;
}
Ссылка на документацию: https://developer.apple.com/documentation/uikit/uitextinput/1614518-caretrectforposition
Обновление: Swift 2.x или Swift 3.x
Смотрите ответ Нейта.
Обновление: Swift 4.x
Для Swift 4.x используйте caretRect(for position: UITextPosition) → CGRect
.
import UIKit
class MyTextView: UITextView {
override func caretRect(for position: UITextPosition) -> CGRect {
var superRect = super.caretRect(for: position)
guard let font = self.font else { return superRect }
// "descender" is expressed as a negative value,
// so to add its height you must subtract its value
superRect.size.height = font.pointSize - font.descender
return superRect
}
}
Ссылка на документацию: https://developer.apple.com/documentation/uikit/uitextinput/1614518-caretrect