Skip to content

Commit

Permalink
Merge pull request #237 from wordpress-mobile/issue/fixing-scaled-fon…
Browse files Browse the repository at this point in the history
…t-api

WPStyleGuide: ScaledFont now matches the requested weight
  • Loading branch information
jleandroperez authored Jan 13, 2020
2 parents a73e3d4 + 95c63f2 commit a4f4f0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion WordPressShared.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "WordPressShared"
s.version = "1.8.11"
s.version = "1.8.12"
s.summary = "Shared components used in building the WordPress iOS apps and other library components."

s.description = <<-DESC
Expand Down
15 changes: 7 additions & 8 deletions WordPressShared/Core/Views/WPStyleGuide+DynamicType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,13 @@ extension WPStyleGuide {
/// - Returns: the requested scaled font.
///
private class func scaledFont(for style: UIFont.TextStyle, weight: UIFont.Weight) -> UIFont {
let traitCollection = UITraitCollection(preferredContentSizeCategory: .large)
let descriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: style, compatibleWith: traitCollection)

let traits = [UIFontDescriptor.TraitKey.weight: UIFont.Weight.semibold]
let descriptorWithTraits = descriptor.addingAttributes([.traits: traits])
let baseFontWithTraits = UIFont(descriptor: descriptorWithTraits, size: 0)

return UIFontMetrics(forTextStyle: style).scaledFont(for: baseFontWithTraits)
let font = UIFont.preferredFont(forTextStyle: style)
let traits = [UIFontDescriptor.TraitKey.weight: weight]

let descriptorWithTraits = font.fontDescriptor.addingAttributes([.traits: traits])
let size = UIFontMetrics(forTextStyle: style).scaledValue(for: font.pointSize)

return UIFont(descriptor: descriptorWithTraits, size: size)
}

/// Creates a NotoSerif UIFont for the user current text size settings.
Expand Down

0 comments on commit a4f4f0a

Please sign in to comment.