Reputation: 199
I'm making a slider which can be used as a countdown timer, how can I set the value of rangeCircularSlider.startPointValue
to my current time value, because this takes in as a float value. I'm writing this code:
let date=Date()
let calendar=Calendar.current
let hour=calendar.component(.hour, from: date)
let minute=calendar.component(.minute, from: date)
let dayInSeconds = 24 * 60 * 60
rangeCircularSlider.maximumValue = CGFloat(dayInSeconds)
rangeCircularSlider.startPointValue = CGFloat(1 * 60)
rangeCircularSlider.endPointValue = CGFloat(8 * 60)
Upvotes: 1
Views: 1581
Reputation: 1457
You can convert the date to a TimeInterval type (which is a double) and use that as starting point, for example:
let startPointValue = CGFloat(Date().timeIntervalSince1970)
Upvotes: 2
Reputation: 5467
The code gives the time elapsed since the start of third millennium.
let now = Date()
now.timeIntervalSinceReferenceDate
"Mar 27, 2017, 10:35 AM"
512283940.76486
Refer to this link
Upvotes: 1