1 Star 0 Fork 0

PatrickStar / UIKitLivePreview

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

UIKitLivePreview

Enables SwiftUI live previews for UIKit views and view controllers.

uikitlivepreview720

Requirements

  • macOS Catalina or later
  • Xcode 12 or later
  • iOS Deployment Target 12.0 or later

Installation

Swift Package Manager (Recommended)

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"))
]

Carthage

  1. Add UIKitLivePreview to your Cartfile.

    github "nicoelayda/UIKitLivePreview" ~> 1.3.1
  2. Run carthage update --use-xcframeworks

  3. Drag UIKitLivePreview.xcframework in Carthage/Build into your application target's Frameworks, Libraries and Embedded Content.

Cocoapods

  1. Add UIKitLivePreview to your Podfile.

    pod 'UIKitLivePreview', '~> 1.3.1'
  2. Run pod install

Manual Install

Copy the contents of Sources/UIKitLivePreview to your project.

A prebuilt XCFramework binary is also available

Usage

  1. Import UIKitLivePreview in your view or view controller.
  2. In the same Swift file, define a new struct conforming to PreviewProvider.
  3. Inside the previews property:
    • Initialise your UIKit view or view controller.
    • Call preview() on it to create a wrapped SwiftUI View instance.
    • Return the preview instance.
  4. Optionally, you may chain ViewModifiers to customise the preview. See example below.

Example


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.

License

MIT. See LICENSE.

The MIT License (MIT) Copyright (c) 2021 Dominic Elayda Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

UIKitLivePreview 展开 收起
Swift 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/hickeyhao/UIKitLivePreview.git
git@gitee.com:hickeyhao/UIKitLivePreview.git
hickeyhao
UIKitLivePreview
UIKitLivePreview
main

搜索帮助