【Swift】弹出日历选择框

本文介绍了PGActionSheetCalendar组件的使用方法,该组件基于FSCalendar进行了封装,并通过CocoaPods安装。文章详细解释了如何展示日历、设置标题、按钮样式及日历样式,并提供了两种监听选中日期的方法:代理和闭包。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

PGActionSheetCalendar

使用FSCalendar进行封装的

CocoaPods安装

pod 'PGActionSheetCalendar'
复制代码

使用

let calendar = PGActionSheetCalendar()
present(calendar, animated: false, completion: nil)
复制代码

高级用法

有两种监听选中日期的方法

1、代理

calendar.delegate = self

func calendar(_ calendar: PGActionSheetCalendar, didSelectDate components: DateComponents) {
    print("year = ", components.year!,"month = ", components.month!,  "day = ", components.day!)
}
复制代码

2、闭包

calendar.didSelectDateComponents = {components in
    print("year = ", components.year!,"month = ", components.month!,  "day = ", components.day!)
}
复制代码

设置title

let label = calendar.titleLabel
label.text = "PGCalendar"
复制代码

设置按钮的样式

calendar.cancelButton.setTitleColor(UIColor.red, for: .normal)
calendar.sureButton.setTitleColor(UIColor.red, for: .normal)
复制代码

设置日历的样式

github.com/WenchaoD/FS…

转载于:https://juejin.im/post/5a312ce66fb9a0450809a894

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值