YSModalCustomHeight 1.0.0.0

YSModalCustomHeight 1.0.0.0

Maintained by 姚帅.



  • By
  • ys

YSModalCustomHeight

模态弹框,自定义高度,底部与屏幕对齐,顶部为半透明

环境

swift 4

iOS 8+

arm 64

使用步骤

1、导入框架

pod 'YSModalCustomHeight'

2、导入命名空间

import YSModalCustomHeight

使用小技巧

PresentedViewController 使用说明和示例

1、PresentedViewController只需要继承YSModalCustomHeight_presentedVC即可;

2、如果需要自定义高度和遮罩颜色及透明度,实现相应的方法即可;

import UIKit

class PresentedVC: YSModalCustomHeight_presentedVC {

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.orange
    }

    // 如果不实现此方法,默认为屏幕高度一半
    override func ys_setupModalHeight() -> CGFloat {
        return 300
    }

    // 如果不实现方法,遮罩视图默认为黑色、透明度为0.5
    override func ys_setupMaskView() -> (backgroundColor: UIColor, alpha: CGFloat) {
        return (UIColor.black,0.5)
    }

    @IBAction func dismissAction(_ sender: UIButton) {
        dismiss(animated: true, completion: nil)
    }
}

PresentingViewController 使用说明及示例

1、遵守YSModalCustomHeight_protocol,不需要实现协议方法,仅仅遵守即可;

2、在需要Modal展现的地方,调用协议方法即可;

import UIKit

class ViewController: UIViewController,YSModalCustomHeight_protocol{

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @IBAction func modalAction(_ sender: UIButton) {
        let sb = UIStoryboard(name: "Main", bundle: nil)
        let presentedVC = sb.instantiateViewController(withIdentifier: "p") as! YSModalCustomHeight_presentedVC

        ys_present_customHeight(presentedVC: presentedVC, transitionStyle: nil, completion: nil)
    }
}