UIFont - how to get system thin font
You can use system font thin weight:
UIFont.systemFont(ofSize: 34, weight: UIFontWeightThin)
List of available weights for San Francisco:
UIFontWeightUltraLight
UIFontWeightThin
UIFontWeightLight
UIFontWeightRegular
UIFontWeightMedium
UIFontWeightSemibold
UIFontWeightBold
UIFontWeightHeavy
UIFontWeightBlack
As of iOS 11, UIFontWeight*
was renamed to UIFont.Weight.*
. More you can get here https://developer.apple.com/documentation/uikit/uifont.weight.
How to set text font as System Thin in Swift?
The system
font in the Interface Builder is the OS default font, it is not a font you can get by it's name. For the system font Apple provides the following methods:
+ (UIFont *)systemFontOfSize:(CGFloat)fontSize;
+ (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize;
+ (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize;
These do not include any thin version but iOS 8.2 onwards you can use:
+ (UIFont *)systemFontOfSize:(CGFloat)fontSize weight:(CGFloat)weight;
Where you can pass: as weights:
UIFontWeightUltraLight
UIFontWeightThin
UIFontWeightLight
UIFontWeightRegular
UIFontWeightMedium
UIFontWeightSemibold
UIFontWeightBold
UIFontWeightHeavy
So a thin system font would be:
UIFont *thinFont = [UIFont systemFontOfSize:15 weight:UIFontWeightThin];
How to select system font programmatically?
Use .systemFontOfSize
which is available in iOS 8.2 and later. For example:
someLabel.font = UIFont.systemFontOfSize(38.0, weight: UIFontWeightSemibold)
UIFont Class Reference
How to check if UIFont is system font?
Here is your method you want:
-(BOOL)isSystemFont:(UIFont *)font
{
return ([[font familyName] isEqualToString:[[UIFont systemFontOfSize:12.0f] familyName]])?YES:NO;
}
Or as an extension in Swift3
extension UIFont {
func isSystemFont() -> Bool {
return self.familyName == UIFont.systemFont(ofSize: 12.0).familyName
}
}
Above method will return as you need
if([self isSystemFont:systemFont1]) NSLog(@"SystemFont");
else NSLog(@"Custom Font");
if([self isSystemFont:customFont1]) NSLog(@"SystemFont");
else NSLog(@"Custom Font");
Output is
2014-03-04 15:48:18.791 TestProject[4031:70b] SystemFont
2014-03-04 15:48:18.791 TestProject[4031:70b] Custom Font
How can I get weight of a UILabel?
To get the font weight string name, use the font descriptor and pass in the face attribute.
Swift 4.2
let font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.bold)
let face = font.fontDescriptor.object(forKey: UIFontDescriptorFaceAttribute) as! String
print("face: \(face)")
Swift 3
let font = UIFont.systemFont(ofSize: 14, weight: UIFontWeightBold)
let face = font.fontDescriptor.object(forKey: UIFontDescriptorFaceAttribute) as! String
print("face: \(face)")
Related Topics
How Come I Can Cast to Nsmanagedobject But Not to My Entity's Type
Embed a Uiviewcontroller in a Navigationcontroller Using Segues
Wrap Items in a Horizontal Uistackview on Multiple Lines
How to Use Call Directory Extension to Identify a Incoming Call in My Application
What Is Most Common and Correct Practice to Get a Cgfloat from an Nsnumber
Run iPhone as an Ibeacon in the Background
How to Make an iOS Asset Bundle
What Is a Provisioning Profile Used for When Developing iPhone Applications
Allow Unverified Ssl Certificate in Uiwebview
Fatal Error: Init(Coder:) Has Not Been Implemented Error Despite Being Implemented
Local and Push Notifications in iOS Version Compatible
Using Uipageviewcontroller with Swift and Multiple View Controllers
Import Swift Class in Objective-C, <Mymodule>-Swift.H File Not Found
How to Remove Tmp Directory Files of an iOS App
Skspritenode - Create a Round Corner Node
The Document Main.Storyboard Requires Xcode 8.0 or Later
Hardware-Dependent Nsdateformatter Datefromstring: Bug (Returns Nil)