Created
August 13, 2020 19:35
-
-
Save christopherkarani/e46d2b29dcbaf4876d9cb9c3694f8666 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
extension NSMutableAttributedString { | |
var fontSize:CGFloat { return 14 } | |
var boldFont:UIFont { return UIFont(name: "AvenirNext-Bold", size: fontSize) ?? UIFont.boldSystemFont(ofSize: fontSize) } | |
var normalFont:UIFont { return UIFont(name: "AvenirNext-Regular", size: fontSize) ?? UIFont.systemFont(ofSize: fontSize)} | |
func bold(_ value:String) -> NSMutableAttributedString { | |
let attributes:[NSAttributedString.Key : Any] = [ | |
.font : boldFont | |
] | |
self.append(NSAttributedString(string: value, attributes:attributes)) | |
return self | |
} | |
func normal(_ value:String) -> NSMutableAttributedString { | |
let attributes:[NSAttributedString.Key : Any] = [ | |
.font : normalFont, | |
] | |
self.append(NSAttributedString(string: value, attributes:attributes)) | |
return self | |
} | |
/* Other styling methods */ | |
func orangeHighlight(_ value:String) -> NSMutableAttributedString { | |
let attributes:[NSAttributedString.Key : Any] = [ | |
.font : normalFont, | |
.foregroundColor : UIColor.white, | |
.backgroundColor : UIColor.orange | |
] | |
self.append(NSAttributedString(string: value, attributes:attributes)) | |
return self | |
} | |
func blackHighlight(_ value:String) -> NSMutableAttributedString { | |
let attributes:[NSAttributedString.Key : Any] = [ | |
.font : normalFont, | |
.foregroundColor : UIColor.white, | |
.backgroundColor : UIColor.black | |
] | |
self.append(NSAttributedString(string: value, attributes:attributes)) | |
return self | |
} | |
func underlined(_ value:String) -> NSMutableAttributedString { | |
let attributes:[NSAttributedString.Key : Any] = [ | |
.font : normalFont, | |
.underlineStyle : NSUnderlineStyle.single.rawValue | |
] | |
self.append(NSAttributedString(string: value, attributes:attributes)) | |
return self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment