ios - UITextView lineHeightMultiple Clips Top, first line, of Text -
in ios 8, have vanilla uitextview clips top of 1st line when lineheightmultiple applied it's nsmutableparagraphstyle, see image below:

it appears though lineheightmultiple affects 1st line of text in addition subsequent lines.
setting clipstobounds = false on uitextview @ least enable clipped part show, can see image below top part of text above it's frame:

i can fix setting top constraint on offending uitextview compensate clipstobounds = false feels hack me.
i have tried using wkwebview offending text, , setting css line-height property, , works fine. there must missing when comes uitextview though.
additionally, setting linespacing on paragraph style less 0 has no affect, per docs:
the distance in points between bottom of 1 line fragment , top of next. **this value nonnegative.** value included in line fragment heights in layout manager. i have tried setting contentinset of uitextview using system font, both had not affect.
my sample code setup follows:
let text = "this multiline run of text" let font = uifont(name: "myfontname", size: 31.0)! // let font = uifont.systemfontofsize(31.0) let paragraph = nsmutableparagraphstyle() paragraph.lineheightmultiple = 0.75 paragraph.alignment = nstextalignment.center let attributes = [ nsparagraphstyleattributename: paragraph, nsfontattributename: font ] titleview.attributedtext = nsattributedstring(string: text, attributes: attributes) // titleview.contentinset = uiedgeinsets(top: 50.0, left: 0.0, bottom: 0.0, right: 0.0) titleview.clipstobounds = false has encountered , overcome or top constraint hack way go?
i had same issue.
i compensated using nsbaselineoffsetattributename.
you should use:
let attributes = [ nsparagraphstyleattributename: paragraph, nsfontattributename: font, nsbaselineoffsetattributename: -5 ] you have set lower paragraph.lineheightmultiple.
a little tricky, works.
Comments
Post a Comment