Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Text style #31

Merged
merged 6 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The repository uses [DocC](https://www.swift.org/documentation/docc/) for develo
This target contains non-mandatory extension to the Architecture and additional types and Views which
are commonly used.

- ``TextStyle`` (See source documentation)
- ``CameraImagePicker`` (See source documentation)
- ``GalleryImagePicker`` (See source documentation)

Expand Down
112 changes: 112 additions & 0 deletions Sources/FuturedHelpers/Helpers/Font+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#if canImport(UIKit)

import SwiftUI

extension Font.TextStyle {

/// The UIKit dynamic text style to use for fonts.
public var uiFontTextStyle: UIFont.TextStyle {
switch self {
case .largeTitle:
return .largeTitle
case .title:
return .title1
case .title2:
return .title2
case .title3:
return .title3
case .headline:
return .headline
case .subheadline:
return .subheadline
case .body:
return .body
case .callout:
return .callout
case .footnote:
return .footnote
case .caption:
return .caption1
case .caption2:
return .caption2
case .extraLargeTitle:
if #available(iOS 17.0, *) {
return .extraLargeTitle
} else {
return .largeTitle
}
case .extraLargeTitle2:
if #available(iOS 17.0, *) {
return .extraLargeTitle2
} else {
return .largeTitle
}
@unknown default:
return .body
}
}
}

extension Font.Weight {
/// The UIKit weight that represents standard typeface style.
public var uiFontWeight: UIFont.Weight {
switch self {
case .ultraLight:
.ultraLight
case .thin:
.thin
case .regular:
.regular
case .medium:
.medium
case .semibold:
.semibold
case .bold:
.bold
case .heavy:
.heavy
case .black:
.black
default:
.regular
}
}
}

extension Font.Width {
/// AThe UIKit width to use for fonts that have multiple widths.
public var uiFontWidth: UIFont.Width {
switch self {
case .compressed:
.compressed
case .condensed:
.condensed
case .expanded:
.expanded
case .standard:
.standard
default:
.standard
}
}
}

extension Font.Design {
/// The UIKit design that describes the system-defined typeface designs.
public var uiDesign: UIFontDescriptor.SystemDesign {
switch self {
case .default:
.default
case .monospaced:
.monospaced
case .rounded:
.rounded
case .serif:
.serif
@unknown default:
.default
}
}
}

#endif
Loading
Loading