Go to file
MiguelSchulz f09cd02c31
Merge pull request #1 from yazio/Typo-fix
Fix several typos
2022-05-30 11:56:51 +02:00
.github Use ruby/setup-ruby 2022-05-23 13:17:32 +02:00
Sources/ReadabilityModifier Code style adjustments 2022-05-24 12:53:30 +02:00
Tests/ReadabilityModifierTests Code style adjustments 2022-05-24 12:53:30 +02:00
example_images Resize README images 2022-05-30 11:32:32 +02:00
.gitignore Resize README images 2022-05-30 11:32:32 +02:00
CHANGELOG.md Create CHANGELOG.md 2022-05-30 11:35:26 +02:00
Gemfile Add Gemfile 2022-05-23 08:35:12 +02:00
Gemfile.lock Update to Bundler V2 2022-05-23 13:11:34 +02:00
LICENSE Add License 2022-05-20 11:38:20 +02:00
Package.swift Initial commit 2022-05-20 11:35:54 +02:00
README.md Fix several typos 2022-05-30 11:44:17 +02:00
Rakefile Downgrade to iOS simulator 15.2 for tests 2022-05-23 13:23:57 +02:00

README.md

Test package

ReadabilityModifier

UIKits readableContentGuide for every SwiftUI View, in the form of a ViewModifier

What it is

Displaying multiple lines of text in a single column can make it hard to read the text and easy to lose track of the lines - especially on devices with a great screen width, like iPads.

With the modifier applied:

Without the modifier:

With iOS 9.0, Apple introduced readableContentGuide - a layout guide representing an area with a readable width within the view.

UI components that follow this layout guide automatically adjust their width accordingly to provide a better reading experience, while taking screen size, orientation, multitasking and even dynamic type size into account.

What this package does

Since readableContentGuide is part of UIKit, there is no direct alternative in SwiftUI. Alternative solutions, like applying a bigger padding depending on the horizontal size class, do not consider the variety of combinations of screen size, dynamic type size, etc.

ReadabilityModifier provides a simple ViewModifier that ports the original behavior of UIKits readableContentGuide to every SwiftUI View that it is applied to - either by setting the width of the view, or by adding horizontal padding.

Usage

Apply .fitToReadableContentGuide() on any SwiftUI View to add horizontal padding that places the view inside the readableContentGuide

var body: some View {
    VStack {
        Text("This text could be waaaaay longer...")
            .fitToReadableContentGuide()
    }
}

You can add extra spacing that is added on top of the readableContentGuide

Text("This text needs some more room")
     .fitToReadableContentGuide(extraSpacing: 20)

The default way the readableContentGuide is respected is by adding a horizontal padding to the view. In some cases, e.g. when the view is already placed in a VStack that already has padding, this padding will add up and make the text smaller than intended. By changing the type property, you can also set the width of the view - this uses the .frame() function to respect the readableContentGuide

VStack {
    Text("This text is already in a padded container, so I will rather set its width")
        .fitToReadableContentGuide(type: .width)
}
.padding(100)

Install

Adding ReadabilityModifier as a package dependency

  1. Go to Xcode -> Project Settings and select your Project
  2. Select Tab Package Dependencies and click the +
  3. Paste https://github.com/yazio/ReadabilityModifier in the search bar and click on "Add Package"
  4. Select the target(s) in which you want to use ReadabilityModifier

Swift Package Manager

Add ReadabilityModifier as a package dependency, like shown in the example below:

// swift-tools-version:5.6

import PackageDescription

let package = Package(
  name: "YourProject",
  platforms: [
       .iOS(.v14),
  ],
  dependencies: [
    .package(name: "ReadabilityModifier", url: "https://github.com/yazio/ReadabilityModifier.git", .branch("main"))
  ],
  targets: [
    .target(name: "YourProject", dependencies: ["ReadabilityModifier"])
  ]
)

We are hiring

If you are interested in working on a well architected Nutrition & Health-App in a fully remote position, we'd love to hear from you! Check our open positions and feel free to reach out if you have any questions.