EzPopup

Version License Platform

什么是 EzPopup

如果您正在苦苦寻找一种在 iOS 设备上将视图或视图控制器显示为弹窗的方法,那么这个 pod 就是为您准备的。 使用 EzPopup,您可以轻松显示弹窗,如下所示:

Custom alert at center Custom picker at bottom

示例

要运行示例项目,请克隆 repo,然后首先从 Example 目录运行 pod install

兼容性

安装

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/huynguyencong/EzPopup.git", .upToNextMajor(from: "1.0.0"))
]

或者

File > Swift Packages > Add Package Dependency 添加 https://github.com/huynguyencong/EzPopup.git 选择 "Up to Next Major" 并设置为 "1.0.0"

Cocoapods

EzPopup 可通过 CocoaPods 获得。 要安装它,只需将以下行添加到您的 Podfile 中

pod 'EzPopup'

用法

使用弹窗视图控制器非常简单

首先,使用您要显示的视图或视图控制器初始化一个 PopupViewController

// init YourViewController
let contentViewController = ...

// Init popup view controller with content is your content view controller. 
// You can let your content view determine pop up size by using its intrinsic size by setting popupWidth and popupHeight nil.
// You can also set position by the position param. If you want show a pop up below a view, use .offsetFromView for position param.
let popupVC = PopupViewController(contentController: contentViewController, popupWidth: 100, popupHeight: 200)

// show it by call present(_ , animated:) method from a current UIViewController
present(popupVC, animated: true)

可选:您可以自定义 PopupViewController 的某些属性。 例如

popupVC.backgroundAlpha = 0.3
popupVC.backgroundColor = .black
popupVC.canTapOutsideToDismiss = true
popupVC.cornerRadius = 10
popupVC.shadowEnabled = true

SwiftUI 版本

SwiftUI 弹窗

作者

huynguyencong, conghuy2012@gmail.com

许可证

EzPopup 在 MIT 许可证下可用。 有关更多信息,请参见 LICENSE 文件。