This is the problem:
What I have done?
I have set a paragraph Style to this text:
let titleParagraphStyle = NSMutableParagraphStyle()
titleParagraphStyle.alignment = .natural
titleParagraphStyle.paragraphSpacing = 33
let attributes = [NSParagraphStyleAttributeName: titleParagraphStyle]
This of course made the cursor to be HUGE all the time, so after this I overrided caretfor and all is OK until selection of the text:
override func caretRect(for position: UITextPosition) -> CGRect {
var original = super.caretRect(for: position)
guard let isFont = self.font else { return original }
original.size.height = isFont.pointSize - isFont.descender
return original
}
What I am missing here? How can I make the selection handles to be equal size than the text?
Currently you are literally changing the spacing attribute of your text which, in no way is possible to change the selecting cursor's size. What you can do is just programmatically make spacing in the textDidChange
when you detect that the yourTextField.attributedText?.size().width
passes a certain distance. I presume that you aren't copying and pasting, so just that will work. Let me know otherwise.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.