MKAPopupKit 3.1.1

MKAPopupKit 3.1.1

Hituzi Ando 维护。



  • 作者
  • Hituzi Ando

MKAPopupKit

MKAPopupKit 是一个框架,为 iOS 提供简单且可定制的弹出视图。请看以下示例。

要求

  • iOS 13.0+
  • Xcode 11.6+

开始使用

将框架安装到您的 iOS 应用中

您有三种方式来安装此框架。

1. CocoaPods

MKAPopupKit 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中:

pod "MKAPopupKit"

2. Carthage

您可以使用 Carthage 通过将其添加到 Cartfile 来安装 MKAPopupKit。

github "HituziANDO/MKAPopupKit"

如果您使用 Carthage 构建依赖项,请确保您已经将 MKAPopupKit.framework 添加到目标的“框架、库和嵌入内容”部分,并将它们包含在您的 Carthage 框架复制构建阶段中。

3. 手动安装

  1. 下载最新的 MKAPopupKit 框架,并将其复制到您的 Xcode 项目中。
  2. 打开“常规”面板。
  3. 在“框架、库和嵌入内容”部分下单击 '+' 按钮。
  4. 点击“添加其他...”后,选择 MKAPopupKit.xcframework。

快速使用

  1. 导入框架。

    import MKAPopupKit
  2. 创建一个实例。

    让我们看看以下代码。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
  3. 显示弹出窗口。

    popup.show()
  4. 隐藏弹出窗口。

    popup.hide()

动画类型

MKAPopup 有一些显示和隐藏弹出窗口的动画。

淡入淡出

向上滑动

向下滑动

向左滑动

向右滑动

通告框

通告框是一种在显示几秒短消息后自动消失的视图。它受到安卓系统Toast的启发。

最简单用法

非常简单!请看以下内容。

MKAToast("Display short message!").show()

自定义通告框

自定义通告框的视图并显示它。

// Make the style.
let config = MKAToastStyleConfiguration()
config.width = 320.0
config.height = 56.0
config.backgroundColor = UIColor.red.withAlphaComponent(0.9)
config.textColor = .black
config.font = UIFont.systemFont(ofSize: 17.0, weight: .bold)

// Create the toast with options.
MKAToast("Something error occurred!", style: config)
    .withDelegate(self)
    .withTag(1)
    .withTime(MKAToastTimeLong)
    .withAnimationDuration(0.5)
    .withDelay(0.5)
    .show()

指示器

MKAIndicator让您轻松创建功能强大的指示器视图。请参见以下示例。

基本类型指示器

自定义类型指示器

精灵动画类型指示器

最简单用法

  1. 将指示器设置为默认可以使用单例模式

    // ViewController
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        // Set new indicator as default.
        MKAIndicator.setDefault(MKAIndicator(activityIndicatorViewStyle: .medium))
    }
  2. 显示指示器

    MKAIndicator.default().showIgnoringUserInteraction(false)
  3. 隐藏指示器

    MKAIndicator.default().hide()

样式

基本类型指示器

基本类型指示器使用UIKit准备好的样式简洁易用。

// Show the basic indicator.
let indicator = MKAIndicator(activityIndicatorViewStyle: .medium)
indicator.showIgnoringUserInteraction(false)

自定义类型指示器

自定义类型指示器使用您创建或准备好的指示器图像。指示器图像自动在指定的动画间隔内旋转。

// Show the custom indicator with the image.
let indicator = MKAIndicator(image: UIImage(named: "spinner")!)
    .withAnimationDuration(2.0)
indicator.showIgnoringUserInteraction(false)

精灵动画类型指示器

精灵动画类型指示器使用您创建或准备好的指示器图像。图像由指定动画间隔的关键帧动画组成。

// Show the sprite animation indicator.
let indicator = MKAIndicator(imagesFormat: "indicator%d", count: 8)
    .withAnimationDuration(0.5)
indicator.showIgnoringUserInteraction(false)

禁用用户交互

当忽略用户交互为真时,如果指示器显示,用户无法操作。

let indicator = MKAIndicator(image: UIImage(named: "spinner")!)
    .withAnimationDuration(2.0)
    .withOverlayColor(UIColor.white.withAlphaComponent(0.7))
// Show the indicator and disable user interaction.
indicator.showIgnoringUserInteraction(true)

底部菜单

用法

// Creates your content view.
let contentView = ...YOUR CONTENT VIEW CREATION...

// Creates the bottom sheet object.
let bottomSheet = MKABottomSheet(contentView: contentView)

// Sets the sheet height.
bottomSheet.sheetHeight = 320.0

// Sets the delegate (for MKAPopupDelegate).
bottomSheet.delegate = self

// Shows the bottom sheet.
bottomSheet.show()

// Hides the bottom sheet.
bottomSheet.hide()

更多信息,请参考我的 示例代码