Skip to content

Instantly share code, notes, and snippets.

@ptsakyrellis
Created March 14, 2016 21:15
Show Gist options
  • Save ptsakyrellis/86298a470dd2f737465c to your computer and use it in GitHub Desktop.
Save ptsakyrellis/86298a470dd2f737465c to your computer and use it in GitHub Desktop.
UIFont extensions to be able to get bold and bold italic fonts directlky from a UIFont object
/**
UIFont extensions to be able to get bold and bold italic fonts directlky
from a UIFont object
*/
import Foundation
import UIKit
extension UIFont {
func withTraits(traits:UIFontDescriptorSymbolicTraits...) -> UIFont {
let descriptor = self.fontDescriptor()
.fontDescriptorWithSymbolicTraits(UIFontDescriptorSymbolicTraits(traits))
return UIFont(descriptor: descriptor, size: 0)
}
func boldItalic() -> UIFont {
return withTraits(.TraitBold, .TraitCondensed)
}
func bold() -> UIFont {
return withTraits(.TraitBold)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment