UIFontDescriptor
is pretty powerful class and can be used to get bold version of the font you want. It should be totally safe and future proof as it only requires usage of public API and doesn't depend on any string modifications.
Here is the code in Swift 3:
extension UIFont {
func bold() -> UIFont? {
let fontDescriptorSymbolicTraits: UIFontDescriptorSymbolicTraits = [fontDescriptor.symbolicTraits, .traitBold]
let bondFontDescriptor = fontDescriptor.withSymbolicTraits(fontDescriptorSymbolicTraits)
return bondFontDescriptor.flatMap { UIFont(descriptor: $0, size: pointSize) }
}
}
Here is the code in objective-c:
@implementation UIFont (RABoldFont)
- (UIFont *)ra_boldFont
{
UIFontDescriptor *fontDescriptor = [self fontDescriptor];
UIFontDescriptorSymbolicTraits traits = fontDescriptor.symbolicTraits;
traits = traits | UIFontDescriptorTraitBold;
UIFontDescriptor *boldFontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits:traits];
return [UIFont fontWithDescriptor:boldFontDescriptor size:self.pointSize];
}
@end
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…