2014-11-24 21:51:43 +01:00
|
|
|
//
|
2018-01-25 19:53:39 +01:00
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
2014-11-24 21:51:43 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "UIFont+OWS.h"
|
|
|
|
|
2018-01-25 19:53:39 +01:00
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
2014-11-24 21:51:43 +01:00
|
|
|
@implementation UIFont (OWS)
|
|
|
|
|
2017-11-30 22:19:36 +01:00
|
|
|
+ (UIFont *)ows_thinFontWithSize:(CGFloat)size
|
|
|
|
{
|
2018-02-23 18:46:04 +01:00
|
|
|
return [UIFont systemFontOfSize:size weight:UIFontWeightThin];
|
2014-11-24 21:51:43 +01:00
|
|
|
}
|
|
|
|
|
2017-11-30 22:19:36 +01:00
|
|
|
+ (UIFont *)ows_lightFontWithSize:(CGFloat)size
|
|
|
|
{
|
2018-02-23 18:46:04 +01:00
|
|
|
return [UIFont systemFontOfSize:size weight:UIFontWeightLight];
|
2014-11-24 21:51:43 +01:00
|
|
|
}
|
|
|
|
|
2017-11-30 22:19:36 +01:00
|
|
|
+ (UIFont *)ows_regularFontWithSize:(CGFloat)size
|
|
|
|
{
|
2018-02-23 18:46:04 +01:00
|
|
|
return [UIFont systemFontOfSize:size weight:UIFontWeightRegular];
|
2014-11-24 21:51:43 +01:00
|
|
|
}
|
|
|
|
|
2017-11-30 22:19:36 +01:00
|
|
|
+ (UIFont *)ows_mediumFontWithSize:(CGFloat)size
|
|
|
|
{
|
2018-02-23 18:46:04 +01:00
|
|
|
return [UIFont systemFontOfSize:size weight:UIFontWeightMedium];
|
2014-12-06 19:26:01 +01:00
|
|
|
}
|
|
|
|
|
2017-11-30 22:19:36 +01:00
|
|
|
+ (UIFont *)ows_boldFontWithSize:(CGFloat)size
|
|
|
|
{
|
2015-09-01 19:22:08 +02:00
|
|
|
return [UIFont boldSystemFontOfSize:size];
|
2014-11-24 21:51:43 +01:00
|
|
|
}
|
|
|
|
|
2017-03-14 21:01:12 +01:00
|
|
|
#pragma mark - Icon Fonts
|
|
|
|
|
|
|
|
+ (UIFont *)ows_fontAwesomeFont:(CGFloat)size
|
|
|
|
{
|
|
|
|
return [UIFont fontWithName:@"FontAwesome" size:size];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (UIFont *)ows_dripIconsFont:(CGFloat)size
|
|
|
|
{
|
|
|
|
return [UIFont fontWithName:@"dripicons-v2" size:size];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (UIFont *)ows_elegantIconsFont:(CGFloat)size
|
|
|
|
{
|
|
|
|
return [UIFont fontWithName:@"ElegantIcons" size:size];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Dynamic Type
|
2015-12-26 17:27:27 +01:00
|
|
|
|
2018-04-06 22:28:34 +02:00
|
|
|
+ (UIFont *)ows_dynamicTypeTitle1Font
|
2017-11-30 22:19:36 +01:00
|
|
|
{
|
2018-04-06 22:28:34 +02:00
|
|
|
return [UIFont preferredFontForTextStyle:UIFontTextStyleTitle1];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (UIFont *)ows_dynamicTypeTitle2Font
|
|
|
|
{
|
|
|
|
return [UIFont preferredFontForTextStyle:UIFontTextStyleTitle2];
|
2015-12-26 17:27:27 +01:00
|
|
|
}
|
|
|
|
|
2018-04-06 22:28:34 +02:00
|
|
|
+ (UIFont *)ows_dynamicTypeTitle3Font
|
|
|
|
{
|
|
|
|
return [UIFont preferredFontForTextStyle:UIFontTextStyleTitle3];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (UIFont *)ows_dynamicTypeHeadlineFont
|
|
|
|
{
|
|
|
|
return [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
|
|
|
|
}
|
|
|
|
|
2018-07-09 21:28:14 +02:00
|
|
|
+ (UIFont *)ows_dynamicTypeBodyFont
|
2016-10-06 21:47:45 +02:00
|
|
|
{
|
2018-07-09 21:28:14 +02:00
|
|
|
return [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
|
2016-10-06 21:47:45 +02:00
|
|
|
}
|
|
|
|
|
2018-07-09 21:28:14 +02:00
|
|
|
+ (UIFont *)ows_dynamicTypeSubheadlineFont
|
|
|
|
{
|
|
|
|
return [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
|
2018-04-06 22:28:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (UIFont *)ows_dynamicTypeFootnoteFont
|
2017-04-17 21:13:15 +02:00
|
|
|
{
|
|
|
|
return [UIFont preferredFontForTextStyle:UIFontTextStyleFootnote];
|
|
|
|
}
|
|
|
|
|
2018-04-06 22:28:34 +02:00
|
|
|
+ (UIFont *)ows_dynamicTypeCaption1Font
|
2017-11-30 22:19:36 +01:00
|
|
|
{
|
2018-04-06 22:28:34 +02:00
|
|
|
return [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];
|
2016-10-06 15:44:25 +02:00
|
|
|
}
|
|
|
|
|
2018-04-06 22:28:34 +02:00
|
|
|
+ (UIFont *)ows_dynamicTypeCaption2Font
|
2017-08-14 22:18:54 +02:00
|
|
|
{
|
2018-04-06 22:28:34 +02:00
|
|
|
return [UIFont preferredFontForTextStyle:UIFontTextStyleCaption2];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Styles
|
|
|
|
|
|
|
|
- (UIFont *)ows_italic
|
|
|
|
{
|
|
|
|
return [self styleWithSymbolicTraits:UIFontDescriptorTraitItalic];
|
|
|
|
}
|
|
|
|
|
2018-04-10 19:02:33 +02:00
|
|
|
- (UIFont *)ows_bold
|
|
|
|
{
|
|
|
|
return [self styleWithSymbolicTraits:UIFontDescriptorTraitBold];
|
|
|
|
}
|
|
|
|
|
2018-04-06 22:28:34 +02:00
|
|
|
- (UIFont *)styleWithSymbolicTraits:(UIFontDescriptorSymbolicTraits)symbolicTraits
|
|
|
|
{
|
|
|
|
UIFontDescriptor *fontDescriptor = [self.fontDescriptor fontDescriptorWithSymbolicTraits:symbolicTraits];
|
|
|
|
UIFont *font = [UIFont fontWithDescriptor:fontDescriptor size:0];
|
|
|
|
OWSAssert(font);
|
|
|
|
return font ?: self;
|
|
|
|
}
|
|
|
|
|
2018-04-16 18:39:11 +02:00
|
|
|
- (UIFont *)ows_mediumWeight
|
2018-04-06 22:28:34 +02:00
|
|
|
{
|
|
|
|
// The recommended approach of deriving "medium" weight fonts for dynamic
|
|
|
|
// type fonts is:
|
|
|
|
//
|
|
|
|
// [UIFontDescriptor fontDescriptorByAddingAttributes:...]
|
|
|
|
//
|
|
|
|
// But this doesn't seem to work in practice on iOS 11 using UIFontWeightMedium.
|
|
|
|
|
|
|
|
UIFont *derivedFont = [UIFont systemFontOfSize:self.pointSize weight:UIFontWeightMedium];
|
2018-04-09 22:27:05 +02:00
|
|
|
return derivedFont;
|
2017-08-14 22:18:54 +02:00
|
|
|
}
|
|
|
|
|
2014-11-24 21:51:43 +01:00
|
|
|
@end
|
2018-01-25 19:53:39 +01:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|