Skip to content

Commit

Permalink
✨ Add FontModifier
Browse files Browse the repository at this point in the history
  • Loading branch information
leinhauplk authored and olejnjak committed Nov 3, 2023
1 parent f7d0999 commit 1037611
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
34 changes: 34 additions & 0 deletions ACKategories-iOS/SwiftUIExtensions/FontModifier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import SwiftUI

@available(iOSApplicationExtension 14.0, *)
extension View {
/// Sets font and line height for text in this view.
///
/// - Parameters:
/// - font: The font to use in this view.
/// - lineHeight: The line height to use in this view.
/// - textStyle: The text style for relative font scaling. If `nil`is specified then dynamic type is turned off.
func font(
_ font: UIFont,
lineHeight: Double,
textStyle: Font.TextStyle?
) -> some View {
let customFont: Font

// Do not scale font based on dynamic type when nil `relativeTo` specified
if let textStyle = textStyle {
customFont = .custom(
font.fontName,
size: font.pointSize,
relativeTo: textStyle
)
} else {
customFont = Font(font)
}

return self
.font(customFont)
.lineSpacing(lineHeight - font.lineHeight)
.padding(.vertical, (lineHeight - font.lineHeight) / 2)
}
}
13 changes: 13 additions & 0 deletions ACKategories.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
69FA5FBD23C868A900B44BCD /* ModalFlowCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69FA5FAC23C868A900B44BCD /* ModalFlowCoordinator.swift */; };
69FA5FC223C8690A00B44BCD /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 69FA5FC123C8690A00B44BCD /* LaunchScreen.storyboard */; };
6A31C9F3250572FE0047A983 /* SelfSizingTableHeaderFooterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A31C9F2250572FE0047A983 /* SelfSizingTableHeaderFooterView.swift */; };
6A572DB92ADE89B0002BD518 /* FontModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A572DB82ADE89B0002BD518 /* FontModifier.swift */; };
88EDD90425B8252E00207987 /* GradientViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88EDD90325B8252E00207987 /* GradientViewController.swift */; };
A33559012555270F009B9D89 /* FlowCoordinatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A33559002555270F009B9D89 /* FlowCoordinatorTests.swift */; };
A38883E3257E2D2D00B958DD /* ErrorHandlers.swift in Sources */ = {isa = PBXBuildFile; fileRef = A38883E2257E2D2D00B958DD /* ErrorHandlers.swift */; };
Expand Down Expand Up @@ -265,6 +266,7 @@
69FA5FC323C869A200B44BCD /* ACKategories.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; path = ACKategories.podspec; sourceTree = "<group>"; };
69FA5FE423C8712D00B44BCD /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
6A31C9F2250572FE0047A983 /* SelfSizingTableHeaderFooterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelfSizingTableHeaderFooterView.swift; sourceTree = "<group>"; };
6A572DB82ADE89B0002BD518 /* FontModifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FontModifier.swift; sourceTree = "<group>"; };
88EDD90325B8252E00207987 /* GradientViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradientViewController.swift; sourceTree = "<group>"; };
A33559002555270F009B9D89 /* FlowCoordinatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowCoordinatorTests.swift; sourceTree = "<group>"; };
A38883E2257E2D2D00B958DD /* ErrorHandlers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorHandlers.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -450,6 +452,8 @@
69E81A0823C773370054687B /* ACKategories-iOS */ = {
isa = PBXGroup;
children = (
6950963023C7747C00E8F457 /* Base */,
6A572DB72ADE8994002BD518 /* SwiftUIExtensions */,
697CECF023C877B20019FE61 /* Aliases.swift */,
A38883E2257E2D2D00B958DD /* ErrorHandlers.swift */,
6950964823C7751600E8F457 /* GradientView.swift */,
Expand Down Expand Up @@ -588,6 +592,14 @@
path = "Flow coordinators";
sourceTree = "<group>";
};
6A572DB72ADE8994002BD518 /* SwiftUIExtensions */ = {
isa = PBXGroup;
children = (
6A572DB82ADE89B0002BD518 /* FontModifier.swift */,
);
path = SwiftUIExtensions;
sourceTree = "<group>";
};
88EDD8FD25B824C200207987 /* GradientView */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -979,6 +991,7 @@
6950967023C78AC900E8F457 /* UIControlEvents.swift in Sources */,
6950965723C7754D00E8F457 /* Reusable.swift in Sources */,
69F83E972A617A2500E9C8EA /* Combine+Concurrency.swift in Sources */,
6A572DB92ADE89B0002BD518 /* FontModifier.swift in Sources */,
6950962A23C7740B00E8F457 /* Logger.swift in Sources */,
6950967823C78AC900E8F457 /* UIViewController+Children.swift in Sources */,
6950967223C78AC900E8F457 /* UIViewExtensions.swift in Sources */,
Expand Down

0 comments on commit 1037611

Please sign in to comment.