Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bielikb/uiviewpreview
Mattt's beautiful gist to gain SwiftUI previews for your UIViews turned into Swift Package.
https://github.com/bielikb/uiviewpreview
ios mattt nshipster preview swiftui uikit
Last synced: about 2 months ago
JSON representation
Mattt's beautiful gist to gain SwiftUI previews for your UIViews turned into Swift Package.
- Host: GitHub
- URL: https://github.com/bielikb/uiviewpreview
- Owner: bielikb
- License: unlicense
- Created: 2020-02-07T10:54:58.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-02-08T13:09:57.000Z (almost 5 years ago)
- Last Synced: 2024-10-30T17:16:04.702Z (2 months ago)
- Topics: ios, mattt, nshipster, preview, swiftui, uikit
- Language: Swift
- Homepage:
- Size: 752 KB
- Stars: 29
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
_Mattt's_ beautiful gist to gain SwiftUI previews for your UIViews turned into Swift Package.
# UIViewPreview Swift Package
Swift Package contains:
* `UIViewPreview`
* `UIViewControllerPreview`Please read more about the use-cases for `UIViewPreview` in the `NSHipster` blogpost:
[https://nshipster.com/swiftui-previews/](https://nshipster.com/swiftui-previews/)## Requirements:
* macOS Catalina
* Xcode 11.0 and above
* Swift 5.1 and above
* iOS 13.0 and above
* tvOS 13.0 and above## Installation
### Swift Package ManagerAdd
`.package(url: "https://github.com/bielikb/UIViewPreview.git", from: "1.0.0")`
to your `Package.swift` file's `dependencies`.If youre using Xcode 11.0 add `UIViewPreview` Swift Package to your target(s) using Xcode.
## PreviewProvider (Official Apple Docs)
```
/// Produces view previews in Xcode.
///
/// Xcode statically discovers types that conform to `PreviewProvider` and
/// generates previews in the canvas for each provider it discovers.
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public protocol PreviewProvider : _PreviewProvider
```## Example:
```
import UIViewPreview#if canImport(SwiftUI) && DEBUG
import SwiftUI
@available(iOS 13.0, *)
struct Label_Preview: PreviewProvider {
static var previews: some View {
UIViewPreview {
let label = UILabel()
label.frame = CGRect(origin: .zero,
size: CGSize(width: 100, height: 100))
label.text = "Text previewed in SwiftUI Preview"
return label
}
}
}
#endif
```![Sample](assets/screenshot.png)
## LICENSE
https://unlicense.org