Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
more customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
hongxinhope committed Apr 12, 2017
1 parent 14e898e commit 22e7ff8
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 8 deletions.
31 changes: 30 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
Carthage/
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/
Carthage/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
".gitignore" 68L, 1458C
8 changes: 8 additions & 0 deletions RecurrencePicker/CustomRecurrenceViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ internal class CustomRecurrenceViewController: UITableViewController {
internal var recurrenceRule: RecurrenceRule!
internal var backgroundColor: UIColor?
internal var separatorColor: UIColor?
internal var supportedFrequencies = Constant.frequencies
internal var maximumInterval = Constant.pickerMaxRowCount

fileprivate var isShowingPickerView = false
fileprivate var pickerViewStyle: PickerViewCellStyle = .frequency
Expand Down Expand Up @@ -182,6 +184,12 @@ extension CustomRecurrenceViewController {
cell.style = pickerViewStyle
cell.frequency = recurrenceRule.frequency
cell.interval = recurrenceRule.interval
let supportedFrequencies: [RecurrenceFrequency] = {
let frequencies = self.supportedFrequencies.filter { Constant.frequencies.contains($0) }.sorted { $0.number < $1.number }
return frequencies.isEmpty ? Constant.frequencies : frequencies
}()
cell.supportedFrequencies = supportedFrequencies
cell.maximumInterval = max(maximumInterval, 1)

return cell
} else if isSelectorViewCell(at: indexPath) {
Expand Down
22 changes: 18 additions & 4 deletions RecurrencePicker/PickerViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ internal class PickerViewCell: UITableViewCell {
}
}
}
internal var supportedFrequencies = Constant.frequencies {
didSet {
if style == .frequency, supportedFrequencies != oldValue {
pickerView.reloadComponent(0)
}
}
}
internal var interval = 1 {
didSet {
if style == .interval {
Expand All @@ -46,6 +53,13 @@ internal class PickerViewCell: UITableViewCell {
}
}
}
internal var maximumInterval = Constant.pickerMaxRowCount {
didSet {
if style == .interval, maximumInterval != oldValue {
pickerView.reloadComponent(0)
}
}
}

override func awakeFromNib() {
super.awakeFromNib()
Expand All @@ -62,10 +76,10 @@ extension PickerViewCell: UIPickerViewDataSource, UIPickerViewDelegate {
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
switch style {
case .frequency:
return Constant.frequencies.count
return supportedFrequencies.count
case .interval:
if component == 0 {
return Constant.pickerMaxRowCount
return maximumInterval
} else {
return 1
}
Expand All @@ -75,7 +89,7 @@ extension PickerViewCell: UIPickerViewDataSource, UIPickerViewDelegate {
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
switch style {
case .frequency:
return Constant.frequencyStrings()[row]
return Constant.frequencyStrings()[supportedFrequencies[row].number]
case .interval:
if component == 0 {
return String(row + 1)
Expand All @@ -93,7 +107,7 @@ extension PickerViewCell: UIPickerViewDataSource, UIPickerViewDelegate {
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
switch style {
case .frequency:
frequency = Constant.frequencies[row]
frequency = supportedFrequencies[row]
delegate?.pickerViewCell(self, didSelectFrequency: frequency)
case .interval:
if component == 0 {
Expand Down
4 changes: 4 additions & 0 deletions RecurrencePicker/RecurrencePicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ open class RecurrencePicker: UITableViewController {
open var occurrenceDate = Date()
open var backgroundColor: UIColor?
open var separatorColor: UIColor?
open var supportedCustomRecurrenceFrequencies = Constant.frequencies
open var customRecurrenceMaximumInterval = Constant.pickerMaxRowCount

fileprivate var isModal: Bool {
return presentingViewController?.presentedViewController == self
Expand Down Expand Up @@ -130,6 +132,8 @@ extension RecurrencePicker {
customRecurrenceViewController.tintColor = tintColor
customRecurrenceViewController.backgroundColor = backgroundColor
customRecurrenceViewController.separatorColor = separatorColor
customRecurrenceViewController.supportedFrequencies = supportedCustomRecurrenceFrequencies
customRecurrenceViewController.maximumInterval = customRecurrenceMaximumInterval
customRecurrenceViewController.delegate = self

var rule = recurrenceRule ?? RecurrenceRule.dailyRecurrence()
Expand Down
2 changes: 1 addition & 1 deletion RecurrencePicker/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.0.6</string>
<string>0.0.7</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
2 changes: 2 additions & 0 deletions RecurrencePickerExample/ExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class ExampleViewController: UIViewController {
recurrencePicker.occurrenceDate = occurrenceDate
recurrencePicker.backgroundColor = UIColor(white: 242 / 255, alpha: 1)
recurrencePicker.separatorColor = UIColor(white: 221 / 255, alpha: 1)
// recurrencePicker.supportedCustomRecurrenceFrequencies = [.weekly, .monthly, .hourly, .daily]
// recurrencePicker.customRecurrenceMaximumInterval = 10
recurrencePicker.delegate = self
navigationController?.pushViewController(recurrencePicker, animated: true)
// present(UINavigationController(rootViewController: recurrencePicker), animated: true, completion: nil)
Expand Down
4 changes: 2 additions & 2 deletions RecurrencePickerExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.0.6</string>
<string>0.0.7</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>6</string>
<string>7</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
Expand Down

0 comments on commit 22e7ff8

Please sign in to comment.