added test properties
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
91eb645ebb
commit
16ee851d44
@ -20,7 +20,8 @@ extension NSAttributedString {
|
|||||||
|
|
||||||
extension NSMutableAttributedString {
|
extension NSMutableAttributedString {
|
||||||
public static func mutableText(for text: String, textStyle: TextStyle, textColor: UIColor, alignment: NSTextAlignment = .left, lineBreakMode: NSLineBreakMode) -> 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)
|
let attributedString = NSMutableAttributedString(string: text, attributes: startingAttributes)
|
||||||
|
|
||||||
//get the range
|
//get the range
|
||||||
@ -35,13 +36,22 @@ extension NSMutableAttributedString {
|
|||||||
paragraph.alignment = alignment
|
paragraph.alignment = alignment
|
||||||
paragraph.lineBreakMode = lineBreakMode
|
paragraph.lineBreakMode = lineBreakMode
|
||||||
|
|
||||||
|
if textStyle.lineSpacing > 0 {
|
||||||
|
paragraph.lineSpacing = textStyle.lineSpacing
|
||||||
|
}
|
||||||
|
|
||||||
//set lineHeight
|
//set lineHeight
|
||||||
if textStyle.lineHeight > 0.0 {
|
if textStyle.lineHeight > 0.0 {
|
||||||
let lineHeight = textStyle.lineHeight
|
let lineHeight = textStyle.lineHeight
|
||||||
paragraph.maximumLineHeight = lineHeight
|
// if textStyle.lineHeight > textStyle.pointSize {
|
||||||
paragraph.minimumLineHeight = lineHeight
|
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)
|
attributedString.addAttribute( .paragraphStyle, value: paragraph, range: entireRange)
|
||||||
|
|
||||||
return attributedString
|
return attributedString
|
||||||
|
|||||||
@ -29,6 +29,8 @@ public struct TextStyle: Equatable, RawRepresentable {
|
|||||||
public let lineHeight: CGFloat
|
public let lineHeight: CGFloat
|
||||||
public let letterSpacing: CGFloat
|
public let letterSpacing: CGFloat
|
||||||
public let fontFace: Font
|
public let fontFace: Font
|
||||||
|
public let lineSpacing: CGFloat
|
||||||
|
public let baselineOffset: CGFloat
|
||||||
|
|
||||||
public init?(rawValue: String) {
|
public init?(rawValue: String) {
|
||||||
guard let style = TextStyle.textStyle(for: rawValue) else { return nil }
|
guard let style = TextStyle.textStyle(for: rawValue) else { return nil }
|
||||||
@ -37,14 +39,18 @@ public struct TextStyle: Equatable, RawRepresentable {
|
|||||||
self.lineHeight = style.lineHeight
|
self.lineHeight = style.lineHeight
|
||||||
self.letterSpacing = style.letterSpacing
|
self.letterSpacing = style.letterSpacing
|
||||||
self.fontFace = style.fontFace
|
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.rawValue = rawValue
|
||||||
self.fontFace = fontFace
|
self.fontFace = fontFace
|
||||||
self.pointSize = pointSize
|
self.pointSize = pointSize
|
||||||
self.lineHeight = lineHeight
|
self.lineHeight = lineHeight
|
||||||
self.letterSpacing = letterSpacing
|
self.letterSpacing = letterSpacing
|
||||||
|
self.lineSpacing = lineSpacing
|
||||||
|
self.baselineOffset = baselineOffset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user