diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSContactOffersCell.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSContactOffersCell.m index e772b1ba5..253c39bf1 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSContactOffersCell.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSContactOffersCell.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "OWSContactOffersCell.h" @@ -100,12 +100,12 @@ NS_ASSUME_NONNULL_BEGIN - (UIFont *)titleFont { - return [UIFont ows_mediumFontWithSize:16.f]; + return UIFont.ows_dynamicTypeBodyFont.ows_medium; } - (UIFont *)buttonFont { - return [UIFont ows_regularFontWithSize:14.f]; + return UIFont.ows_dynamicTypeBodyFont; } - (CGFloat)hMargin diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m index da1cfcb1b..bba575e0c 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m @@ -91,7 +91,7 @@ NS_ASSUME_NONNULL_BEGIN { OWSAssert(DisplayableText.kMaxJumbomojiCount == 5); - CGFloat basePointSize = [UIFont ows_dynamicTypeBodyFont].pointSize; + CGFloat basePointSize = UIFont.ows_dynamicTypeBodyFont.pointSize; switch (self.displayableBodyText.jumbomojiCount) { case 0: break; @@ -108,7 +108,7 @@ NS_ASSUME_NONNULL_BEGIN break; } - return [UIFont ows_dynamicTypeBodyFont]; + return UIFont.ows_dynamicTypeBodyFont; } #pragma mark - Convenience Accessors @@ -946,7 +946,7 @@ NS_ASSUME_NONNULL_BEGIN - (UIFont *)tapForMoreFont { - return [UIFont ows_regularFontWithSize:12.f]; + return UIFont.ows_dynamicTypeCaption1Font; } - (CGFloat)tapForMoreHeight diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m index 9cf6cae7a..6382649c8 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m @@ -62,13 +62,13 @@ NS_ASSUME_NONNULL_BEGIN [self.contentView addSubview:self.footerView]; self.dateHeaderLabel = [UILabel new]; - self.dateHeaderLabel.font = [UIFont ows_regularFontWithSize:12.f]; + self.dateHeaderLabel.font = self.dateHeaderDateFont; self.dateHeaderLabel.textAlignment = NSTextAlignmentCenter; self.dateHeaderLabel.textColor = [UIColor lightGrayColor]; [self.contentView addSubview:self.dateHeaderLabel]; self.footerLabel = [UILabel new]; - self.footerLabel.font = [UIFont ows_regularFontWithSize:12.f]; + self.footerLabel.font = UIFont.ows_dynamicTypeCaption1Font; self.footerLabel.textColor = [UIColor lightGrayColor]; [self.footerView addSubview:self.footerLabel]; @@ -362,12 +362,12 @@ NS_ASSUME_NONNULL_BEGIN - (UIFont *)dateHeaderDateFont { - return [UIFont boldSystemFontOfSize:12.0f]; + return UIFont.ows_dynamicTypeCaption1Font.ows_medium; } - (UIFont *)dateHeaderTimeFont { - return [UIFont systemFontOfSize:12.0f]; + return UIFont.ows_dynamicTypeCaption1Font; } #pragma mark - Measurement diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSQuotedMessageView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSQuotedMessageView.m index 2464dc963..0e2cb5bfa 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSQuotedMessageView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSQuotedMessageView.m @@ -368,7 +368,7 @@ NS_ASSUME_NONNULL_BEGIN - (UIFont *)quotedAuthorFont { - return [UIFont ows_mediumFontWithSize:11.f]; + return UIFont.ows_dynamicTypeCaption1Font.ows_medium; } - (UIColor *)quotedAuthorColor @@ -383,8 +383,6 @@ NS_ASSUME_NONNULL_BEGIN - (UIFont *)quotedTextFont { - // Honor dynamic type in the text. - // TODO: ? return [UIFont ows_dynamicTypeBodyFont]; } @@ -395,11 +393,7 @@ NS_ASSUME_NONNULL_BEGIN - (UIFont *)fileTypeFont { - UIFontDescriptor *fontD = - [self.quotedTextFont.fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitItalic]; - UIFont *font = [UIFont fontWithDescriptor:fontD size:0]; - OWSAssert(font); - return font ?: self.quotedTextFont; + return self.quotedTextFont.ows_italic; } - (UIColor *)filenameTextColor diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSSystemMessageCell.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSSystemMessageCell.m index d84d2f460..d1d6a48b9 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSSystemMessageCell.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSSystemMessageCell.m @@ -25,18 +25,12 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic) UIImageView *imageView; @property (nonatomic) UILabel *titleLabel; -// override from JSQMessagesCollectionViewCell -@property (nonatomic) UILabel *cellTopLabel; - @end #pragma mark - @implementation OWSSystemMessageCell -// override from JSQMessagesCollectionViewCell -@synthesize cellTopLabel = _cellTopLabel; - // `[UIView init]` invokes `[self initWithFrame:...]`. - (instancetype)initWithFrame:(CGRect)frame { @@ -55,12 +49,6 @@ NS_ASSUME_NONNULL_BEGIN self.backgroundColor = [UIColor whiteColor]; - self.cellTopLabel = [UILabel new]; - self.cellTopLabel.textAlignment = NSTextAlignmentCenter; - self.cellTopLabel.font = self.topLabelFont; - self.cellTopLabel.textColor = [UIColor lightGrayColor]; - [self.contentView addSubview:self.cellTopLabel]; - self.imageView = [UIImageView new]; [self.contentView addSubview:self.imageView]; @@ -100,11 +88,6 @@ NS_ASSUME_NONNULL_BEGIN [self setNeedsLayout]; } -- (UIFont *)topLabelFont -{ - return [UIFont boldSystemFontOfSize:12.0f]; -} - - (UIColor *)textColor { return [UIColor colorWithRGBHex:0x303030]; @@ -223,7 +206,7 @@ NS_ASSUME_NONNULL_BEGIN - (UIFont *)titleFont { - return [UIFont ows_regularFontWithSize:13.f]; + return UIFont.ows_dynamicTypeFootnoteFont; } - (CGFloat)hMargin @@ -260,22 +243,15 @@ NS_ASSUME_NONNULL_BEGIN CGFloat contentWidth = ([self iconSize] + [self hSpacing] + titleSize.width); - CGSize topLabelSize = [self.cellTopLabel sizeThatFits:CGSizeMake(self.contentView.width, CGFLOAT_MAX)]; - self.cellTopLabel.frame = CGRectMake(0, 0, self.contentView.frame.size.width, topLabelSize.height); - - CGFloat topLabelSpacing = topLabelSize.height; - CGFloat contentLeft = round((self.contentView.width - contentWidth) * 0.5f); CGFloat imageLeft = ([self isRTL] ? round(contentLeft + contentWidth - [self iconSize]) : contentLeft); CGFloat titleLeft = ([self isRTL] ? contentLeft : round(imageLeft + [self iconSize] + [self hSpacing])); - self.imageView.frame = CGRectMake(imageLeft, - round((self.contentView.height - [self iconSize] + topLabelSpacing) * 0.5f), - [self iconSize], - [self iconSize]); + self.imageView.frame = CGRectMake( + imageLeft, round((self.contentView.height - [self iconSize]) * 0.5f), [self iconSize], [self iconSize]); self.titleLabel.frame = CGRectMake(titleLeft, - round((self.contentView.height - titleSize.height + topLabelSpacing) * 0.5f), + round((self.contentView.height - titleSize.height) * 0.5f), ceil(titleSize.width + 1.f), ceil(titleSize.height + 1.f)); } diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSUnreadIndicatorCell.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSUnreadIndicatorCell.m index 86eec804e..88ca54b48 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSUnreadIndicatorCell.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSUnreadIndicatorCell.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "OWSUnreadIndicatorCell.h" @@ -101,12 +101,12 @@ NS_ASSUME_NONNULL_BEGIN - (UIFont *)titleFont { - return [UIFont ows_regularFontWithSize:16.f]; + return UIFont.ows_dynamicTypeBodyFont; } - (UIFont *)subtitleFont { - return [UIFont ows_regularFontWithSize:12.f]; + return UIFont.ows_dynamicTypeCaption1Font; } - (NSString *)titleForInteraction:(TSUnreadIndicatorInteraction *)interaction diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 9204448df..77c2fd8a9 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -1101,7 +1101,7 @@ typedef enum : NSUInteger { name = [self.contactsManager attributedStringForConversationTitleWithPhoneIdentifier:self.thread.contactIdentifier primaryFont:[self navigationBarTitleLabelFont] - secondaryFont:[UIFont ows_footnoteFont]]; + secondaryFont:[UIFont ows_regularFontWithSize:11.f]]; } self.title = nil; diff --git a/Signal/src/ViewControllers/InboxTableViewCell.m b/Signal/src/ViewControllers/InboxTableViewCell.m index fb53a4b66..4695783db 100644 --- a/Signal/src/ViewControllers/InboxTableViewCell.m +++ b/Signal/src/ViewControllers/InboxTableViewCell.m @@ -341,9 +341,10 @@ const NSUInteger kAvatarViewDiameter = 52; name = [[NSAttributedString alloc] initWithString:thread.name]; } } else { - name = [contactsManager attributedStringForConversationTitleWithPhoneIdentifier:thread.contactIdentifier - primaryFont:self.nameLabel.font - secondaryFont:[UIFont ows_footnoteFont]]; + name = [contactsManager + attributedStringForConversationTitleWithPhoneIdentifier:thread.contactIdentifier + primaryFont:self.nameLabel.font + secondaryFont:[UIFont ows_dynamicTypeFootnoteFont]]; } self.nameLabel.attributedText = name; diff --git a/Signal/src/ViewControllers/MessageDetailViewController.swift b/Signal/src/ViewControllers/MessageDetailViewController.swift index eaac9077c..e2e677ea5 100644 --- a/Signal/src/ViewControllers/MessageDetailViewController.swift +++ b/Signal/src/ViewControllers/MessageDetailViewController.swift @@ -232,7 +232,7 @@ class MessageDetailViewController: OWSViewController, MediaDetailPresenter, Medi // We use the "short" status message to avoid being redundant with the section title. statusLabel.text = shortStatusMessage statusLabel.textColor = UIColor.ows_darkGray - statusLabel.font = UIFont.ows_footnote + statusLabel.font = .ows_dynamicTypeFootnote statusLabel.adjustsFontSizeToFitWidth = true statusLabel.sizeToFit() cell.accessoryView = statusLabel diff --git a/Signal/src/ViewControllers/ProfileViewController.m b/Signal/src/ViewControllers/ProfileViewController.m index 3d3d63e14..440442516 100644 --- a/Signal/src/ViewControllers/ProfileViewController.m +++ b/Signal/src/ViewControllers/ProfileViewController.m @@ -179,7 +179,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat UILabel *infoLabel = [UILabel new]; infoLabel.textColor = [UIColor ows_darkGrayColor]; - infoLabel.font = [UIFont ows_footnoteFont]; + infoLabel.font = [UIFont ows_dynamicTypeFootnoteFont]; infoLabel.textAlignment = NSTextAlignmentCenter; NSMutableAttributedString *text = [NSMutableAttributedString new]; [text appendAttributedString:[[NSAttributedString alloc] diff --git a/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m b/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m index 0f044aa17..32c4a639d 100644 --- a/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m +++ b/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m @@ -382,7 +382,7 @@ NS_ASSUME_NONNULL_BEGIN subtitleLabel.text = NSLocalizedString(@"DISAPPEARING_MESSAGES_DESCRIPTION", @"subheading in conversation settings"); subtitleLabel.textColor = [UIColor blackColor]; - subtitleLabel.font = [UIFont ows_footnoteFont]; + subtitleLabel.font = [UIFont ows_dynamicTypeFootnoteFont]; subtitleLabel.numberOfLines = 0; subtitleLabel.lineBreakMode = NSLineBreakByWordWrapping; [cell.contentView addSubview:subtitleLabel]; @@ -421,7 +421,7 @@ NS_ASSUME_NONNULL_BEGIN UILabel *rowLabel = strongSelf.disappearingMessagesDurationLabel; [strongSelf updateDisappearingMessagesDurationLabel]; rowLabel.textColor = [UIColor blackColor]; - rowLabel.font = [UIFont ows_footnoteFont]; + rowLabel.font = [UIFont ows_dynamicTypeFootnoteFont]; rowLabel.lineBreakMode = NSLineBreakByTruncatingTail; [topView addSubview:rowLabel]; [rowLabel autoVCenterInSuperview]; diff --git a/Signal/src/views/AttachmentPointerView.swift b/Signal/src/views/AttachmentPointerView.swift index b4df6efd7..fdb22d125 100644 --- a/Signal/src/views/AttachmentPointerView.swift +++ b/Signal/src/views/AttachmentPointerView.swift @@ -118,7 +118,7 @@ class AttachmentPointerView: UIView { statusLabel.numberOfLines = 2 statusLabel.textColor = self.textColor - statusLabel.font = UIFont.ows_footnote + statusLabel.font = .ows_dynamicTypeFootnote statusLabel.autoPinWidthToSuperview() statusLabel.autoPinEdge(.top, to: .bottom, of: progressView, withOffset: 4) diff --git a/Signal/src/views/GroupTableViewCell.swift b/Signal/src/views/GroupTableViewCell.swift index 2c080f76f..b91f2e73b 100644 --- a/Signal/src/views/GroupTableViewCell.swift +++ b/Signal/src/views/GroupTableViewCell.swift @@ -24,8 +24,8 @@ import SignalServiceKit self.contentView.addSubview(textContainer) // Font config - nameLabel.font = UIFont.ows_dynamicTypeBody - subtitleLabel.font = UIFont.ows_footnote + nameLabel.font = .ows_dynamicTypeBody + subtitleLabel.font = .ows_dynamicTypeFootnote subtitleLabel.textColor = UIColor.ows_darkGray // Listen to notifications... diff --git a/Signal/src/views/QuotedReplyPreview.swift b/Signal/src/views/QuotedReplyPreview.swift index b8d70af3a..dbe9ee0fe 100644 --- a/Signal/src/views/QuotedReplyPreview.swift +++ b/Signal/src/views/QuotedReplyPreview.swift @@ -40,7 +40,7 @@ class QuotedReplyPreview: UIView { let bodyLabel: UILabel = UILabel() bodyLabel.textColor = foregroundColor - bodyLabel.font = .ows_footnote + bodyLabel.font = .ows_dynamicTypeFootnote bodyLabel.text = { if let contentType = quotedReply.contentType { diff --git a/SignalMessaging/Views/ContactTableViewCell.m b/SignalMessaging/Views/ContactTableViewCell.m index 37d3d36eb..85d0794b9 100644 --- a/SignalMessaging/Views/ContactTableViewCell.m +++ b/SignalMessaging/Views/ContactTableViewCell.m @@ -83,12 +83,12 @@ const CGFloat kContactTableViewCellAvatarTextMargin = 12; _profileNameLabel = [UILabel new]; _profileNameLabel.lineBreakMode = NSLineBreakByTruncatingTail; - _profileNameLabel.font = [UIFont ows_footnoteFont]; + _profileNameLabel.font = [UIFont ows_dynamicTypeFootnoteFont]; _profileNameLabel.textColor = [UIColor grayColor]; [_nameContainerView addSubview:_profileNameLabel]; _subtitle = [UILabel new]; - _subtitle.font = [UIFont ows_footnoteFont]; + _subtitle.font = [UIFont ows_dynamicTypeFootnoteFont]; _subtitle.textColor = [UIColor ows_darkGrayColor]; [_nameContainerView addSubview:self.subtitle]; diff --git a/SignalMessaging/categories/UIFont+OWS.h b/SignalMessaging/categories/UIFont+OWS.h index 715f5bf52..d9379f32c 100644 --- a/SignalMessaging/categories/UIFont+OWS.h +++ b/SignalMessaging/categories/UIFont+OWS.h @@ -18,8 +18,6 @@ NS_ASSUME_NONNULL_BEGIN + (UIFont *)ows_boldFontWithSize:(CGFloat)size; -+ (UIFont *)ows_dynamicTypeBodyFont:(CGFloat)size; - #pragma mark - Icon Fonts + (UIFont *)ows_fontAwesomeFont:(CGFloat)size; @@ -28,11 +26,20 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Dynamic Type -@property (class, readonly, nonatomic) UIFont *ows_dynamicTypeBodyFont; +@property (class, readonly, nonatomic) UIFont *ows_dynamicTypeTitle1Font; @property (class, readonly, nonatomic) UIFont *ows_dynamicTypeTitle2Font; +@property (class, readonly, nonatomic) UIFont *ows_dynamicTypeTitle3Font; @property (class, readonly, nonatomic) UIFont *ows_dynamicTypeHeadlineFont; -@property (class, readonly, nonatomic) UIFont *ows_infoMessageFont; -@property (class, readonly, nonatomic) UIFont *ows_footnoteFont; +@property (class, readonly, nonatomic) UIFont *ows_dynamicTypeSubheadlineFont; +@property (class, readonly, nonatomic) UIFont *ows_dynamicTypeBodyFont; +@property (class, readonly, nonatomic) UIFont *ows_dynamicTypeFootnoteFont; +@property (class, readonly, nonatomic) UIFont *ows_dynamicTypeCaption1Font; +@property (class, readonly, nonatomic) UIFont *ows_dynamicTypeCaption2Font; + +#pragma mark - Styles + +- (UIFont *)ows_italic; +- (UIFont *)ows_medium; @end diff --git a/SignalMessaging/categories/UIFont+OWS.m b/SignalMessaging/categories/UIFont+OWS.m index 87532213b..a7f48e761 100644 --- a/SignalMessaging/categories/UIFont+OWS.m +++ b/SignalMessaging/categories/UIFont+OWS.m @@ -33,11 +33,6 @@ NS_ASSUME_NONNULL_BEGIN return [UIFont boldSystemFontOfSize:size]; } -+ (UIFont *)ows_dynamicTypeBodyFont:(CGFloat)size -{ - return [UIFont ows_dynamicTypeBodyFont]; -} - #pragma mark - Icon Fonts + (UIFont *)ows_fontAwesomeFont:(CGFloat)size @@ -57,29 +52,85 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Dynamic Type -+ (UIFont *)ows_dynamicTypeBodyFont ++ (UIFont *)ows_dynamicTypeTitle1Font { - return [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; + return [UIFont preferredFontForTextStyle:UIFontTextStyleTitle1]; +} + ++ (UIFont *)ows_dynamicTypeTitle2Font +{ + return [UIFont preferredFontForTextStyle:UIFontTextStyleTitle2]; } -+ (UIFont *)ows_infoMessageFont ++ (UIFont *)ows_dynamicTypeTitle3Font +{ + return [UIFont preferredFontForTextStyle:UIFontTextStyleTitle3]; +} + ++ (UIFont *)ows_dynamicTypeHeadlineFont +{ + return [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]; +} + ++ (UIFont *)ows_dynamicTypeSubheadlineFont { return [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]; } -+ (UIFont *)ows_footnoteFont ++ (UIFont *)ows_dynamicTypeBodyFont +{ + return [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; +} + ++ (UIFont *)ows_dynamicTypeFootnoteFont { return [UIFont preferredFontForTextStyle:UIFontTextStyleFootnote]; } -+ (UIFont *)ows_dynamicTypeTitle2Font ++ (UIFont *)ows_dynamicTypeCaption1Font { - return [UIFont preferredFontForTextStyle:UIFontTextStyleTitle2]; + return [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1]; } -+ (UIFont *)ows_dynamicTypeHeadlineFont ++ (UIFont *)ows_dynamicTypeCaption2Font { - return [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]; + return [UIFont preferredFontForTextStyle:UIFontTextStyleCaption2]; +} + +#pragma mark - Styles + +- (UIFont *)ows_italic +{ + return [self styleWithSymbolicTraits:UIFontDescriptorTraitItalic]; +} + +- (UIFont *)styleWithSymbolicTraits:(UIFontDescriptorSymbolicTraits)symbolicTraits +{ + UIFontDescriptor *fontDescriptor = [self.fontDescriptor fontDescriptorWithSymbolicTraits:symbolicTraits]; + UIFont *font = [UIFont fontWithDescriptor:fontDescriptor size:0]; + OWSAssert(font); + return font ?: self; +} + +- (UIFont *)ows_medium +{ + // 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]; + + if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(11, 0)) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpartial-availability" + return [[UIFontMetrics defaultMetrics] scaledFontForFont:derivedFont]; +#pragma clang diagnostic pop + } else { + return derivedFont; + } } @end