Swiftpack.co - xiiagency/SwiftUIGrid as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by xiiagency.
xiiagency/SwiftUIGrid 1.0.0
An open source library that provides extensions to SwiftUI libraries to enable spacing/font grids and other advanced utilities
⭐️ 1
🕓 1 week ago
iOS macOS watchOS
.package(url: "https://github.com/xiiagency/SwiftUIGrid.git", from: "1.0.0")

SwiftUIGrid Library

GitHub

An open source library that provides extensions to SwiftUI libraries to enable spacing/font grids and other advanced utilities.

Developed as re-usable components for various projects at XII's iOS, macOS, and watchOS applications.

Installation

Swift Package Manager

  1. In Xcode, select File > Swift Packages > Add Package Dependency.
  2. Follow the prompts using the URL for this repository
  3. Select the SwiftUIGrid library to add to your project

Dependencies

License

See the LICENSE file.

Padding extensions (Source)

extension View {
  func padding(
    top: CGFloat = 0.0,
    trailing: CGFloat = 0.0,
    bottom: CGFloat = 0.0,
    leading: CGFloat = 0.0
  ) -> some View
}

Sets the padding in each directions to the provided values. If a specific direction value is not provided, it is assumed to be 0.0.


extension View {
  func padding(
    vertical: CGFloat = 0.0,
    horizontal: CGFloat = 0.0
  ) -> some View
}

A variant of padding(top:trailing:bottom:leading) that sets vertical/horizontal padding.


extension View {
  func systemPadding() -> some View
}

Resets a View's padding to the system calculated default values.

Structure font definitions (Source)

struct FontFace : Hashable {
  let name: String?
  
  let weight: Font.Weight
  
  let design: Font.Design
  
  init(
    name: String? = nil,
    weight: Font.Weight = .regular,
    design: Font.Design = .default
  )
  
  func toFont(size: CGFloat) -> Font
  
  func toFont<Size : RawRepresentable>(size: Size) -> Font
    where Size.RawValue == CGFloat
}

Defines an optionally named font face with a specific weight, allowing it to be converted to a Font or an NSAttributedString.

An application can define its custom fonts as extensions to this struct, for example:

extension FontFace {
  static let MyCustomFont = FontFace(name: "MyCustomFont", weight: .light)
  static let MySystemFont = FontFace(weight: .light)
}

FontFace attributes support on iOS

extension FontFace {
  func toAttributes(size: CGFloat) -> [NSAttributedString.Key : UIFont]
  
  func toAttributes<Size : RawRepresentable>(
    size: Size
  ) -> [NSAttributedString.Key : UIFont] where Size.RawValue == CGFloat
}

FontFace attributes support on macOS

extension FontFace {
  func toAttributes(size: CGFloat) -> [NSAttributedString.Key : NSFont]
  
  func toAttributes<Size : RawRepresentable>(
    size: Size
  ) -> [NSAttributedString.Key : NSFont] where Size.RawValue == CGFloat
}

Animating FontFace size (Source)

extension View {
  func withAnimatedFont(
    face: FontFace,
    size: CGFloat
  ) -> some View
}

Applies the given font face/size styling to the View but allows for the font size to be animatable.


extension View {
  func withAnimatedFont<Size : RawRepresentable>(
    face: FontFace,
    size: Size
  ) -> some View where Size.RawValue == CGFloat
}

Applies the given font face/size styling to the View but allows for the font size (taken from an enum raw value) to be animatable.

GitHub

link
Stars: 1
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

1.0.0
1 week ago

Initial public release

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics