Swiftpack.co - outrowender/UIViewCanvas as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by outrowender.
outrowender/UIViewCanvas 0.0.8
This package allows you to quickly setup Xcode canvas to any UIView/ViewController.
⭐️ 14
🕓 2 weeks ago
iOS
.package(url: "https://github.com/outrowender/UIViewCanvas.git", from: "0.0.8")

UIViewCanvas

This package allows you to quickly setup Xcode canvas to any UIView/ViewController.

Why?

Run emulator everytime you need to test a small change in your View is painfull.

Requirements

✓ Xcode 11+
✓ Swift 4.2+
✓ iOS 13+ project

How to use?

Step 1

Select your project on Xcode and go to Files > Add Packages and paste this repository URL https://github.com/outrowender/UIViewCanvas on search field.

Select a version and click Install.

Step 2

Add the previewer to the end of your view file:

import SwiftUI
import UIViewCanvas

struct MyPreview: PreviewProvider {
    static var previews: some View {
        ViewCanvas(for: MyCustomUIView())
    }
}

You can instantiate a entire ViewController as well, using ViewControllerCanvas:

struct MyPreview: PreviewProvider {
    static var previews: some View {
        ViewControllerCanvas(for: MyViewController())
    }
}

If you want to customize your preview, check Group component and use a .previewLayout to set a custom canvas to your preview.

struct MyPreview: PreviewProvider {
    static var previews: some View {
        Group{
            ViewCanvas(for: MyCustomUIView())
        }
        .previewLayout(.fixed(width: 350, height: 350))
    }
}

Step 3

You may need to reopen your .swift file in Xcode.

You can use ⌥ + ⌘ + P to quickly resume your canvas.

Credits

This package was a insight that I got from a @bhlvoong video.

GitHub

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

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