Logical Ranges and Character Ranges
In my recent post titled “The Rake and Its Prongs” I introduced a function towards the end, called NSRange.isValidInsertionPointLocation(at:)
. It’s used to consider the after-end location as part of the range.
In my recent post titled “The Rake and Its Prongs” I introduced a function towards the end, called NSRange.isValidInsertionPointLocation(at:)
. It’s used to consider the after-end location as part of the range.
In the original post about a cheap way to set the line height in a text view to, say, 150%, the result kind of worked but didn’t look that cool. One issue is that the extra line spacing was exclusively added at the bottom. With the following solution, you’ll get a proper line height with tastefully aligned insertion point and baseline and all.
NSTextView
(and UITextView
for that matter) have a defaultParagraphStyle
attribute where you can set the text’s line height. That works swell – if you display text statically. Once the user can enter something, you can run into trouble: Update 2017-07: I posted a better version without paragraph style attributes that hooks into the NSLayoutManager
delegate callbacks for a more consistent and speedy experience!