i'm trying find height of single line of text using text kit. calculating text height documentation says
note: don’t need use technique find height of single line of text.
nslayoutmanager
methoddefaultlineheightforfont:
returns value. default line height sum of font’s tallest ascender, plus absolute value of deepest descender, plus leading.
however, when checked nslayoutmanager class reference (and testing in xcode) didn't see defaultlineheightforfont:
method. why that? there alternative?
notes:
- i'm not trying set line height.
- there ways this apparently not use text kit. however, since have text kit stack set , documentation seems indicate possible, use text kit.
- i prefer swift answers objective-c ok, too.
update
i did not realize documentation linked os x until read @joshcaswell's comment. looking how in ios.
in textkit, can use layout manager line height using - linefragmentrectforglyphatindex:effectiverange:
. notice name of function, named "line fragment". why? because not case layout has complete line, instead might have exclusion path (that contains shape or image) text wrapped around it. in case have part of line (line fragment) text laid out.
in delegate of layout manager, implement function might follows:
-(void)layoutmanager:(nslayoutmanager *)layoutmanager didcompletelayoutfortextcontainer:(nstextcontainer *)textcontainer atend:(bool)layoutfinishedflag{ //this first glyph cgrect linefragmentrect = [layoutmanager linefragmentusedrectforglyphatindex:0 effectiverange:nil]; // height of rect line height. }
Comments
Post a Comment