ios - How to count the number of glyphs in NSLayoutManager -


how total number of glyphs in nslayoutmanager?

i making cursor layer overlay on custom text view this:

func movecursortoglyphindex(glyphindex: int) {      // bounding rect glyph     var rect = self.layoutmanager.boundingrectforglyphrange(nsrange(location: glyphindex, length: 1), intextcontainer: view.textcontainer)     rect.origin.y = self.textcontainerinset.top     rect.size.width = cursorwidth      // set cursor layer frame right edge of rect     cursorlayer.frame = rect } 

however, wanted make sure glyphindex not out of bounds. this:

if glyphindex < self.layoutmanager.glyphcount { // doesn't work     // ... } 

i couldn't find right property trial , error, though, , searching online didn't show answers.

i did find in buried in documentation (and seems obvious), since took long time, decided add q&a here.

use numberofglyphs property, in

layoutmanager.numberofglyphs 

this demonstrated in text layout programming guide documentation here.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -