From 7127f9a911178fda64f322071a014e809cf74607 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sat, 27 Apr 2019 09:49:26 -0500 Subject: [PATCH] Change master feed list to use preferred fonts. --- NetNewsWire.xcodeproj/project.pbxproj | 4 +++ iOS/Extensions/UIFont-Extensions.swift | 26 +++++++++++++++++++ .../Cell/MasterFeedTableViewCell.swift | 4 ++- .../MasterFeedTableViewSectionHeader.swift | 7 ++--- .../Cell/MasterFeedUnreadCountView.swift | 16 ++++++------ 5 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 iOS/Extensions/UIFont-Extensions.swift diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index 51306f6a6..0f4c0b386 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -115,6 +115,7 @@ 51F85BF12272524100C787DC /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 51F85BF02272524100C787DC /* Credits.rtf */; }; 51F85BF32272531500C787DC /* Dedication.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 51F85BF22272531500C787DC /* Dedication.rtf */; }; 51F85BF52273625800C787DC /* Bundle-Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51F85BF42273625800C787DC /* Bundle-Extensions.swift */; }; + 51F85BF722749FA100C787DC /* UIFont-Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51F85BF622749FA100C787DC /* UIFont-Extensions.swift */; }; 6581C73820CED60100F4AD34 /* SafariExtensionHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6581C73720CED60100F4AD34 /* SafariExtensionHandler.swift */; }; 6581C73A20CED60100F4AD34 /* SafariExtensionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6581C73920CED60100F4AD34 /* SafariExtensionViewController.swift */; }; 6581C73D20CED60100F4AD34 /* SafariExtensionViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6581C73B20CED60100F4AD34 /* SafariExtensionViewController.xib */; }; @@ -668,6 +669,7 @@ 51F85BF02272524100C787DC /* Credits.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = Credits.rtf; sourceTree = ""; }; 51F85BF22272531500C787DC /* Dedication.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = Dedication.rtf; sourceTree = ""; }; 51F85BF42273625800C787DC /* Bundle-Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Bundle-Extensions.swift"; sourceTree = ""; }; + 51F85BF622749FA100C787DC /* UIFont-Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIFont-Extensions.swift"; sourceTree = ""; }; 6581C73320CED60000F4AD34 /* Subscribe to Feed.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "Subscribe to Feed.appex"; sourceTree = BUILT_PRODUCTS_DIR; }; 6581C73420CED60100F4AD34 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; 6581C73720CED60100F4AD34 /* SafariExtensionHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafariExtensionHandler.swift; sourceTree = ""; }; @@ -975,6 +977,7 @@ 51C4524F226506F400C03939 /* UIImage-Extensions.swift */, 51C4524E226506F400C03939 /* UIStoryboard-Extensions.swift */, 512E092B2268B25500BDCFDD /* UISplitViewController-Extensions.swift */, + 51F85BF622749FA100C787DC /* UIFont-Extensions.swift */, ); path = Extensions; sourceTree = ""; @@ -2261,6 +2264,7 @@ 51C452AE2265104D00C03939 /* TimelineStringFormatter.swift in Sources */, 512E08E62268800D00BDCFDD /* FolderTreeControllerDelegate.swift in Sources */, 51C4529922650A0000C03939 /* ArticleStylesManager.swift in Sources */, + 51F85BF722749FA100C787DC /* UIFont-Extensions.swift in Sources */, 51C452AF2265108300C03939 /* ArticleArray.swift in Sources */, 84F3EE1920DEC97E003FADEB /* FeedSpecifier.swift in Sources */, 51C4528E2265099C00C03939 /* SmartFeedsController.swift in Sources */, diff --git a/iOS/Extensions/UIFont-Extensions.swift b/iOS/Extensions/UIFont-Extensions.swift new file mode 100644 index 000000000..64620b9d1 --- /dev/null +++ b/iOS/Extensions/UIFont-Extensions.swift @@ -0,0 +1,26 @@ +// +// UIFont-Extensions.swift +// NetNewsWire-iOS +// +// Created by Maurice Parker on 4/27/19. +// Copyright © 2019 Ranchero Software. All rights reserved. +// + +import UIKit + +extension UIFont { + + func withTraits(traits:UIFontDescriptor.SymbolicTraits) -> UIFont { + let descriptor = fontDescriptor.withSymbolicTraits(traits) + return UIFont(descriptor: descriptor!, size: 0) //size 0 means keep the size as it is + } + + func bold() -> UIFont { + return withTraits(traits: .traitBold) + } + + func italic() -> UIFont { + return withTraits(traits: .traitItalic) + } + +} diff --git a/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift b/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift index bf85e2e51..0650ed4df 100644 --- a/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift +++ b/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift @@ -86,9 +86,11 @@ class MasterFeedTableViewCell : UITableViewCell { private let titleView: UILabel = { let label = NonIntrinsicLabel() - label.numberOfLines = 1 + label.numberOfLines = 0 label.lineBreakMode = .byTruncatingTail label.allowsDefaultTighteningForTruncation = false + label.adjustsFontForContentSizeCategory = true + label.font = .preferredFont(forTextStyle: .body) return label }() diff --git a/iOS/MasterFeed/Cell/MasterFeedTableViewSectionHeader.swift b/iOS/MasterFeed/Cell/MasterFeedTableViewSectionHeader.swift index d7976eb3a..dc2ef8a32 100644 --- a/iOS/MasterFeed/Cell/MasterFeedTableViewSectionHeader.swift +++ b/iOS/MasterFeed/Cell/MasterFeedTableViewSectionHeader.swift @@ -55,11 +55,12 @@ class MasterFeedTableViewSectionHeader: UITableViewHeaderFooterView { } private let titleView: UILabel = { - let label = UILabel() - label.font = UIFont.boldSystemFont(ofSize: 17.0) - label.numberOfLines = 1 + let label = NonIntrinsicLabel() + label.numberOfLines = 0 label.lineBreakMode = .byTruncatingTail label.allowsDefaultTighteningForTruncation = false + label.adjustsFontForContentSizeCategory = true + label.font = .preferredFont(forTextStyle: .body) return label }() diff --git a/iOS/MasterFeed/Cell/MasterFeedUnreadCountView.swift b/iOS/MasterFeed/Cell/MasterFeedUnreadCountView.swift index 4cfd904ea..fb9aef0c2 100644 --- a/iOS/MasterFeed/Cell/MasterFeedUnreadCountView.swift +++ b/iOS/MasterFeed/Cell/MasterFeedUnreadCountView.swift @@ -8,16 +8,16 @@ import UIKit -private let padding = UIEdgeInsets(top: 1.0, left: 7.0, bottom: 1.0, right: 7.0) -private let cornerRadius = 8.0 -private let bgColor = UIColor.darkGray -private let textColor = UIColor.white -private let textFont = UIFont.systemFont(ofSize: 11.0, weight: UIFont.Weight.semibold) -private var textAttributes: [NSAttributedString.Key: AnyObject] = [NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.font: textFont, NSAttributedString.Key.kern: NSNull()] -private var textSizeCache = [Int: CGSize]() - class MasterFeedUnreadCountView : UIView { + private let padding = UIEdgeInsets(top: 1.0, left: 7.0, bottom: 1.0, right: 7.0) + private let cornerRadius = 8.0 + private let bgColor = UIColor.darkGray + private let textColor = UIColor.white + private let textFont = UIFont.preferredFont(forTextStyle: .caption1) + private lazy var textAttributes: [NSAttributedString.Key: AnyObject] = [NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.font: textFont, NSAttributedString.Key.kern: NSNull()] + private var textSizeCache = [Int: CGSize]() + var unreadCount = 0 { didSet { invalidateIntrinsicContentSize()