Added ability to set items to display in label

This commit is contained in:
Dal Rupnik 2016-08-18 18:55:44 +02:00 committed by GitHub
parent 43d38b5973
commit f52eb0448b
1 changed files with 33 additions and 2 deletions

View File

@ -16,8 +16,15 @@ import UIKit
value = min(maximumValue, max(minimumValue, value))
let isInteger = floor(value) == value
if showIntegerIfDoubleIsInteger && isInteger {
//
// If we have items, we will display them as steps
//
if isInteger && stepValue == 1.0 && items.count > 0 {
label.text = items[Int(value)]
}
else if showIntegerIfDoubleIsInteger && isInteger {
label.text = String(stringInterpolationSegment: Int(value))
} else {
label.text = String(stringInterpolationSegment: value)
@ -225,6 +232,30 @@ import UIKit
}
}
}
public var items : [String] = [] {
didSet {
let isInteger = floor(value) == value
//
// If we have items, we will display them as steps
//
if isInteger && stepValue == 1.0 && items.count > 0 {
var value = Int(self.value)
if value >= items.count {
value = items.count - 1
self.value = Double(value)
}
else {
label.text = items[value]
}
}
}
}
/// Timer used for autorepeat option
var timer: Timer?