【Swift】彈出日曆選擇框

小豬熊發表於2017-12-13

PGActionSheetCalendar.gif

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…

相關文章