All Projects → mrabiciu → UIViewPreviewProvider

mrabiciu / UIViewPreviewProvider

Licence: MIT license
Allows displaying UIViews inside the Xcode preview canvas

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to UIViewPreviewProvider

ColorUp
An easy way to generate strongly typed Swift extensions for either UIColor or Color based off of your colors within the project's asset catalog.
Stars: ✭ 16 (-55.56%)
Mutual labels:  uikit, swiftui
Swiftui Cheat Sheet
SwiftUI 2.0 Cheat Sheet
Stars: ✭ 3,417 (+9391.67%)
Mutual labels:  uikit, swiftui
Movie Trailers SwiftUI
A simple app which shows the lastest movies trailers based on different genres developed using SwiftUI.
Stars: ✭ 51 (+41.67%)
Mutual labels:  uikit, swiftui
Builder
Demonstrates SwiftUI builder patterns for UIKit and networking.
Stars: ✭ 100 (+177.78%)
Mutual labels:  uikit, swiftui
SwiftCurrent
A library for managing complex workflows in Swift
Stars: ✭ 286 (+694.44%)
Mutual labels:  uikit, swiftui
Redux
Manage iOS App state with Redux and Async/Await :)
Stars: ✭ 18 (-50%)
Mutual labels:  uikit, swiftui
CurrencyText
Currency text field formatter available for UIKit and SwiftUI 💶✏️
Stars: ✭ 124 (+244.44%)
Mutual labels:  uikit, swiftui
BottomSheet
Access UISheetPresentationController in SwiftUI on iOS 15 using a simple .bottomSheet modifier.
Stars: ✭ 332 (+822.22%)
Mutual labels:  uikit, swiftui
Render
UIKit a-là SwiftUI.framework [min deployment target iOS10]
Stars: ✭ 2,150 (+5872.22%)
Mutual labels:  uikit, swiftui
About Swiftui
Gathering all info published, both by Apple and by others, about new framework SwiftUI.
Stars: ✭ 5,954 (+16438.89%)
Mutual labels:  uikit, swiftui
SwiftUIKit
📱 UIKit code that is fun to write
Stars: ✭ 71 (+97.22%)
Mutual labels:  uikit, swiftui
VCore
VCore is a Swift collection containing objects, functions, and extensions that I use for my projects
Stars: ✭ 32 (-11.11%)
Mutual labels:  uikit, swiftui
LocalConsole
In-app console and debug tools for iOS developers
Stars: ✭ 595 (+1552.78%)
Mutual labels:  uikit, swiftui
column-text-view-ui
📄 Column Text View is an adaptive UI component that renders text in columns, horizontally [iOS 12, UIKit, TextKit, SwiftUI].
Stars: ✭ 11 (-69.44%)
Mutual labels:  uikit, swiftui
iOS14-Resources
A curated collection of iOS 14 projects ranging from SwiftUI to ML, AR etc.
Stars: ✭ 85 (+136.11%)
Mutual labels:  uikit, swiftui
NativeMarkKit
NativeMark is a flavor of Markdown designed to be rendered by native apps.
Stars: ✭ 36 (+0%)
Mutual labels:  uikit, swiftui
SheeKit
Customize and resize sheets in SwiftUI with SheeKit. Utilise the power of `UISheetPresentationController` and other UIKit features.
Stars: ✭ 56 (+55.56%)
Mutual labels:  uikit, swiftui
Swift Composable Architecture
A library for building applications in a consistent and understandable way, with composition, testing, and ergonomics in mind.
Stars: ✭ 5,199 (+14341.67%)
Mutual labels:  uikit, swiftui
swiftui-example
SwiftUI 示例,技巧和技术集合,帮助我构建应用程序,解决问题以及了解SwiftUI的实际工作方式。
Stars: ✭ 109 (+202.78%)
Mutual labels:  uikit, swiftui
NavigationRouter
A router implementation designed for complex modular apps, written in Swift
Stars: ✭ 89 (+147.22%)
Mutual labels:  uikit, swiftui

UIViewPreviewProvider

This is a helper class for displaying UIViews inside the Xcode preview canvas meant to display SwiftUI.
It allows you to quickly iterate on your UIViews without having to rebuild your entire app.
This is especially useful if your project needs to supports iOS < 13 and you can't start using SwiftUI just yet.

Adding UIViewPreviewProvider to your project.

Just copy UIViewPreviewProvider.swift into your project. I don't think this is large enough to warrant adding a whole library to your project.

Rendering UIView previews in your project

In the file where your view is defined:

// This if check is important if you're working with a project that supports iOS < 13
// If you're working with an iOS 13+ project then you can omit the canImport(SwiftUI) check
#if canImport(SwiftUI) && DEBUG

import SwiftUI

@available(iOS 13.0, *)
struct MyView_Preview: PreviewProvider, UIViewPreviewProvider {
    
    // Provide previews of your UIView
    static let uiPreviews: [Preview] = {

        // Create your views and populate them with some dummy data
        
        let view1 = MyView()
        view1.someProperty = "foo"
        let view1Preview = Preview(view1, displayName: "View 1")

        let view2 = MyView()
        view2.someProperty = "bar"
        let view2Preview = Preview(view2, displayName: "View 2")

        return [view1Preview, view2Preview]
    }()
}

#endif

Open up the preview Xcode canvas by pressing (⌥ + ⌘ + return) and your previews should show up.

You may need to hit the Resume button for them to show up

It should look something like this: screenshot

Examples

See Example.swift for more info.

If you're using MVVM see MVVM Example.swift to see how you can generate previews directly from your ViewModels.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].