I want to define a UIFont as constant value in swift so i can reuse it app to make it consistent. I have used this in Objective-C by #define HelveticaNeue [UIFont fontWithName:@"HelveticaNeue" size:13.0]
I want this code in swift. How can i get this.
I have Used let to define constant in swift and it works on string but not working on UIFont or any other object.
I have also tried other keywords like static, extern,var etc with no success.
struct FontHelper {
static func defaultRegularFontWithSize(size: CGFloat) -> UIFont {
return UIFont(name: "SourceSansPro-Regular", size: size)!
}
static func defaultLightFontWithSize(size: CGFloat) -> UIFont {
return UIFont(name: "SourceSansPro-Light", size: size)!
}
static func defaultSemiBoldFontWithSize(size: CGFloat) -> UIFont {
return UIFont(name: "SourceSansPro-Semibold", size: size)!
}}
To use it: let font = FontHelper.defaultRegularFontWithSize(15)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With