Im making an pickerView with all the month in a year, I would like to create an array with the current month at the beginning of the pickerView and the following month to follow and so on. I already populate the pickerView and the array with all the months and I got the current date too.
let Months = ["January","Febrary","March","April","May","June","July","August","September","October","November","December"]
@IBOutlet var DateLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
DateTime()
}
func DateTime() {
let time = DateFormatter ()
let date = DateFormatter ()
time.timeStyle = .medium
date.dateStyle = .full
print(time.string(from: Date()))
print(date.string(from: Date()))
//RiderTimeStampRequested = time.string(from: Date())
DateLabel.text = date.string(from: Date())
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return Months.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return Months[row]
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
print(Months[row])
}