diff --git a/VDS/Extensions/NSAttributedString.swift b/VDS/Extensions/NSAttributedString.swift index a4b94fb9..ec36fe67 100644 --- a/VDS/Extensions/NSAttributedString.swift +++ b/VDS/Extensions/NSAttributedString.swift @@ -20,7 +20,8 @@ extension NSAttributedString { extension NSMutableAttributedString { public static func mutableText(for text: String, textStyle: TextStyle, textColor: UIColor, alignment: NSTextAlignment = .left, lineBreakMode: NSLineBreakMode) -> NSMutableAttributedString { - let startingAttributes = [NSAttributedString.Key.font: textStyle.font, NSAttributedString.Key.foregroundColor: textColor] + let font = textStyle.font + let startingAttributes = [NSAttributedString.Key.font: font, NSAttributedString.Key.foregroundColor: textColor] let attributedString = NSMutableAttributedString(string: text, attributes: startingAttributes) //get the range @@ -35,13 +36,22 @@ extension NSMutableAttributedString { paragraph.alignment = alignment paragraph.lineBreakMode = lineBreakMode + if textStyle.lineSpacing > 0 { + paragraph.lineSpacing = textStyle.lineSpacing + } + //set lineHeight if textStyle.lineHeight > 0.0 { let lineHeight = textStyle.lineHeight - paragraph.maximumLineHeight = lineHeight - paragraph.minimumLineHeight = lineHeight +// if textStyle.lineHeight > textStyle.pointSize { + paragraph.maximumLineHeight = lineHeight + paragraph.minimumLineHeight = lineHeight +// paragraph.lineHeightMultiple = lineHeight / textStyle.pointSize +// } else { +// paragraph.lineHeightMultiple = lineHeight / font.pointSize +// } } - + attributedString.addAttribute( .baselineOffset, value: textStyle.baselineOffset, range: entireRange) attributedString.addAttribute( .paragraphStyle, value: paragraph, range: entireRange) return attributedString diff --git a/VDS/Typography/Typography.swift b/VDS/Typography/Typography.swift index a89b75de..84c190c1 100644 --- a/VDS/Typography/Typography.swift +++ b/VDS/Typography/Typography.swift @@ -29,6 +29,8 @@ public struct TextStyle: Equatable, RawRepresentable { public let lineHeight: CGFloat public let letterSpacing: CGFloat public let fontFace: Font + public let lineSpacing: CGFloat + public let baselineOffset: CGFloat public init?(rawValue: String) { guard let style = TextStyle.textStyle(for: rawValue) else { return nil } @@ -37,14 +39,18 @@ public struct TextStyle: Equatable, RawRepresentable { self.lineHeight = style.lineHeight self.letterSpacing = style.letterSpacing self.fontFace = style.fontFace + self.lineSpacing = style.lineSpacing + self.baselineOffset = style.baselineOffset } - public init(rawValue: String, fontFace: Font, pointSize: CGFloat = 0.0, lineHeight: CGFloat = 0.0, letterSpacing: CGFloat = 0.0) { + public init(rawValue: String, fontFace: Font, pointSize: CGFloat = 0.0, lineHeight: CGFloat = 0.0, letterSpacing: CGFloat = 0.0, lineSpacing: CGFloat = 0.0, baselineOffset: CGFloat = 0.0) { self.rawValue = rawValue self.fontFace = fontFace self.pointSize = pointSize self.lineHeight = lineHeight self.letterSpacing = letterSpacing + self.lineSpacing = lineSpacing + self.baselineOffset = baselineOffset } }