uifont
UITextView font is nil
Try checking the “selectable” checkbox for this UITextView in Interface Builder. It’s in the Attributes Inspector. Per @VahramDodoryan’s comment below, you can then set selectable to false if you don’t want to support selection. I can’t explain why this works, but it’s probably a UIKit bug. I had an IBOutlet to a UITextView whose font … Read more
How to get monospaced numbers in UILabel on iOS 9
This is now available in UIFont since iOS 9: + (UIFont *)monospacedDigitSystemFontOfSize:(CGFloat)fontSize weight:(CGFloat)weight NS_AVAILABLE_IOS(9_0); eg: [UIFont monospacedDigitSystemFontOfSize:42.0 weight:UIFontWeightMedium]; or in Swift: UIFont.monospacedDigitSystemFont(ofSize: 42.0, weight: UIFontWeightMedium)
How to change an UILabel/UIFont’s letter spacing?
From iOS 6 you can use NSAttributedString in UILabel. In attributed string you can use attribute NSKernAttributeName to set letter spacing NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc] initWithString: @”Test test test test “]; [attrStr addAttribute:NSKernAttributeName value:@(4.0) range:NSMakeRange(0, attrStr.length)]; UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 300, 300, 100)]; label.attributedText = attrStr;
Changing tab bar font in Swift
The UITextAttributeFont was deprecated in iOS 7. You should use the NS variant instead: import UIKit let appearance = UITabBarItem.appearance() let attributes = [NSFontAttributeName:UIFont(name: “American Typewriter”, size: 20)] appearance.setTitleTextAttributes(attributes, forState: .Normal)
How to get the font-size or a bold-version of UIFont instance
This is an old answer and it’s no longer the best solution, please see the accepted answer instead. -(UIFont *)boldFont{ //First get the name of the font (unnecessary, but used for clarity) NSString *fontName = self.fontName; //Some fonts having -Regular on their names. so we have to remove that before append -Bold / -BoldMT fontName … Read more