add headline ascender offset for better look

This commit is contained in:
Pfeil, Scott Robert 2020-07-21 11:31:23 -04:00
parent 0e3c08f341
commit ddcb8bb93c

View File

@ -73,8 +73,11 @@ import Foundation
// When messing with the maximum line height, the baseline needs to be adjusted.
let baseLineOffset = planLabel.font.descender + (overshoot / 2.0)
// We want the top to align with the top of the headline capitals, ignoring ascenders.
let headlineMatchingOffset = headline.font.ascender - headline.font.capHeight
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.maximumLineHeight = planLabel.font.capHeight + overshoot
paragraphStyle.maximumLineHeight = planLabel.font.capHeight + overshoot + headlineMatchingOffset
attributedString.addAttribute(.paragraphStyle, value: paragraphStyle, range: range)
attributedString.addAttribute(.baselineOffset, value: baseLineOffset, range: range)
planLabel.attributedText = attributedString