Skip to content

Nevermole/UIKit-Preview

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UIKit + Preview

This swift package contains wrapper for UIView and UIViewController to display them in SwiftUI Previews.

Installation

Add this project as your swift package dependency in Xcode. How to from Apple is here.

Usage

Use Xcode 11 and in your UIView or UIViewController add the following code to display preview.

UIView

#if canImport(SwiftUI) && DEBUG
import UIKit_Preview
import SwiftUI

@available(iOS 13.0, *)
struct YOUR_UIVIew_Class_Preview: PreviewProvider {
    static var previews: some View {
            View_SwiftUI(YOUR_UIVIew_Class())
    }
}
#endif

UIViewController

#if canImport(SwiftUI) && DEBUG
import UIKit_Preview
import SwiftUI

@available(iOS 13.0, *)
struct YOUR_UIVIewController_Class_Preview: PreviewProvider {
    static var previews: some View {
        ViewController_SwiftUI(controller: YOUR_UIVIewController_Class()
    }
}
#endif

That's it!

There are also two support methods that let you display the views on all device sizes.

  1. .previewOnAllDevices() will display the View on all device sizes with devices bezels.
  2. .previewOnAllSizes(height: Number) will display the View with provided height on all screen widths.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages