MKAPopup
MKAPopup是用Swift编写的,用于iOS的简单且可定制的弹出视图。
Objective-C版本在这里:https://github.com/HituziANDO/MKAPopup/tree/master/MKAPopupObjC
需求
- Swift 5.0+
安装
CocoaPods
MKAPopup可通过CocoaPods获得。要安装它,只需将以下行添加到Podfile中
pod "MKAPopup"
Carthage
您可以使用Carthage将SebasSwift添加到Cartfile进行安装
github "HituziANDO/MKAPopup"
如果您使用Carthage构建您的依赖项,确保您已将MKAPopup.framework添加到目标“链接框架和库”部分,并已在Carthage框架复制构建阶段中包含它们。
手动安装
- 下载最新的 MKAPopup 框架,并将其复制到您的 Xcode 项目中
- 打开“通用”面板
- 在“已嵌入的二进制文件”部分下点击 + 按钮
- 点击“添加其他...”后,选择 MKAPopup.framework
快速使用
让我们看看以下代码。
import MKAPopup
...
// Creates your content view.
let contentView = ...YOUR CONTENT VIEW CREATION...
// Creates a popup using your content view.
let popup = MKAPopup(contentView: contentView)
// Customizes...
// Title (default is nil)
popup.popupView.titleLabel.text = "About Swift"
// Title Text Color (default is system default color)
popup.popupView.titleLabel.textColor = .white
// Title Font (default is system default font)
popup.popupView.titleLabel.font = UIFont.boldSystemFont(ofSize: 20.0)
// Title Text Padding (default is (16, 16, 16, 16))
popup.popupView.titleLabel.padding = UIEdgeInsets(top: 24.0, left: 16.0, bottom: 24.0, right: 16.0)
// Popup Background Color (default is white)
popup.popupView.backgroundColor = UIColor(red: 0, green: 0.5, blue: 1.0, alpha: 1.0)
// Popup Corner Radius (default is 5)
popup.popupView.layer.cornerRadius = 20.0
// Popup Size (default is (300, 400))
popup.popupSize = CGSize(width: 320.0, height: 480.0)
// Overlay Color (default is black with alpha=0.4)
popup.backgroundColor = UIColor.black.withAlphaComponent(0.8)
// Can hide when a user touches up outside a popup (default is true)
popup.canHideWhenTouchUpOutside = false
// Showing Animation (default is fade)
popup.showingAnimation = .fade
// Hiding Animation (default is fade)
popup.hidingAnimation = .fade
// Animation Duration (default is 0.3)
popup.duration = 0.3
// Delegate
popup.delegate = self
// Shows the popup.
popup.show()
...
// Hides the popup.
popup.hide()