Last active
April 10, 2017 04:06
-
-
Save JonFir/dc1e793cb42e02279d6cb9858e5a504a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension NSAttributedString { | |
static func makeAtributes( | |
font: UIFont, | |
lineSpacing: CGFloat? = nil, | |
characterSpacing: CGFloat? = nil, | |
color: UIColor? = nil | |
) -> [String: Any] { | |
var attrs: [String : Any] = [ | |
NSFontAttributeName: font | |
] | |
if let lineSpacing = lineSpacing { | |
let paragraphStyle = NSMutableParagraphStyle() | |
paragraphStyle.lineSpacing = lineSpacing - font.lineHeight | |
attrs[NSParagraphStyleAttributeName] = paragraphStyle | |
} | |
if let characterSpacing = characterSpacing { | |
attrs[NSKernAttributeName] = characterSpacing | |
} | |
if let color = color { | |
attrs[NSForegroundColorAttributeName] = color | |
} | |
return attrs | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment