Enables SwiftUI live previews for UIKit views and view controllers.
In Xcode 13 or later, select File > Add Packages...
In Xcode 12, select File > Swift Packages > Add Package Dependency...
Add https://github.com/nicoelayda/UIKitLivePreview.git
as the package repository URL.
or
If you have an existing Package.swift
file, add UIKitLivePreview
package to your target's dependencies.
dependencies: [
.package(url: "https://github.com/nicoelayda/UIKitLivePreview.git", .upToNextMajor(from: "1.3.1"))
]
Add UIKitLivePreview
to your Cartfile
.
github "nicoelayda/UIKitLivePreview" ~> 1.3.1
Run carthage update --use-xcframeworks
Drag UIKitLivePreview.xcframework
in Carthage/Build
into your application target's Frameworks, Libraries and Embedded Content.
Add UIKitLivePreview
to your Podfile
.
pod 'UIKitLivePreview', '~> 1.3.1'
Run pod install
Copy the contents of Sources/UIKitLivePreview
to your project.
A prebuilt XCFramework binary is also available
UIKitLivePreview
in your view or view controller.PreviewProvider
.previews
property:
preview()
on it to create a wrapped SwiftUI View
instance.ViewModifier
s to customise the preview. See example below.
final class MyViewController: UIViewController { /* ... */ }
#if DEBUG && canImport(SwiftUI)
import SwiftUI
@available(iOS 13.0, *)
struct MyViewController_Preview: PreviewProvider {
static var previews: some View {
MyViewController()
.preview()
.device(.iPhone11)
.landscape()
}
}
#endif
NOTE: If your project is targeting iOS 12, it is recommended to wrap the PreviewProvider
struct in a #if canImport(SwiftUI)
directive and add the @available(iOS 13.0, *)
attribute to it.
Check out UIKitLivePreview-Examples for a sample project.
MIT. See LICENSE.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。