let
temperature
: TKRadialGauge =
TKRadialGauge
()
self
.view
.addSubview
(temperature)
let radialScale =
TKGaugeRadialScale
(minimum:
0
,
maximum
:
100
)
temperature
.addScale
(radialScale)
let freezing : TKGaugeSegment =
TKGaugeSegment
(minimum: -
10
,
maximum
:
0
)
radialScale
.addSegment
(freezing)
let liquid : TKGaugeSegment =
TKGaugeSegment
(minimum:
1
,
maximum
:
99
)
liquid
.fill
=
TKLinearGradientFill
(colors: [
UIColor
(red:
0
.24
,
green
:
0
.52
,
blue
:
0
.78
,
alpha
:
1
.0
),
UIColor
(red:
1
.00
,
green
:
0
.85
,
blue
:
0
.40
,
alpha
:
1
.0
)],
locations
: [
0
,
1
],
startPoint
:
CGPointMake
(
0
,
0
.5
),
endPoint
:
CGPointMake
(
1
,
0
.5
))
radialScale
.addSegment
(liquid)
let boiling =
TKGaugeSegment
(minimum:
100
,
maximum
:
110
)
boiling
.fill
=
TKSolidFill
(color:
UIColor
(red:
0
.90
,
green
:
0
.57
,
blue
:
0
.22
,
alpha
:
1
.0
))
radialScale
.addSegment
(boiling)
let needle : TKGaugeNeedle =
TKGaugeNeedle
() radialScale
.addIndicator
(needle) needle
.setValueAnimated
(
50
,
withDuration
:
1
,
mediaTimingFunction
: kCAMediaTimingFunctionEaseInEaseOut)
self
.view
.addSubview
(temperature)
let radialScale =
TKGaugeRadialScale
(minimum: -
30
,
maximum
:
40
)
radialScale
.ticks
.hidden
=
true
radialScale
.labels
.hidden
=
true
temperature
.addScale
(radialScale)
let mainTemperatureSegment =
TKGaugeSegment
(minimum:-
30
,
maximum
:
40
)
mainTemperatureSegment
.cap
= TKGaugeSegmentCap
.Round
mainTemperatureSegment
.location
=
0
.87
mainTemperatureSegment
.fill
=
TKSolidFill
(color:
UIColor
.whiteColor
()
.colorWithAlphaComponent
(
0
.5
))
mainTemperatureSegment
.width
=
0
.08
radialScale
.addSegment
(mainTemperatureSegment)
let measureTemperatureSegment =
TKGaugeSegment
()
measureTemperatureSegment
.allowTouch
=
true
measureTemperatureSegment
.cap
= TKGaugeSegmentCap
.Round
measureTemperatureSegment
.location
=
0
.9
measureTemperatureSegment
.width
=
0
.14
measureTemperatureSegment
.fill
=
TKLinearGradientFill
(colors: [
UIColor
(red:
0
.27
,
green
:
0
.64
,
blue
:
0
.99
,
alpha
:
1
.0
),
UIColor
(red:
1
.00
,
green
:
0
.74
,
blue
:
0
.00
,
alpha
:
1
.0
)])
measureTemperatureSegment
.shadowOpacity
=
0
.5
measureTemperatureSegment
.shadowOffset
=
CGSizeMake
(
0
,
0
)
radialScale
.addSegment
(measureTemperatureSegment)
temperature
.labelTitle
.text
=
"19C"
temperature
.labelTitle
.font
=
UIFont
(name:
"HelveticaNeue-Light"
,
size
:
35
)
temperature
.labelTitle
.textColor
=
UIColor
.whiteColor
()
measureTemperatureSegment
.allowTouch
=
YES
;
- (
void
)gauge:(
TKGauge
*)gauge
valueChanged
:(CGFloat)value
forScale
:(
TKGaugeScale
*)scale
func
gauge
(gauge: TKGauge, valueChanged
value
: CGFloat, forScale
scale
: TKGaugeScale) {
if
(gauge == temperature) {
temperature
.labelTitle
.text
=
"\(Int(value))˚C"
}
}
measureTemperatureSegment
.setRangeAnimated
(
TKRange
(minimum: -
30
,
andMaximum
:
19
),
withDuration
:
1
.0
,
mediaTimingFunction
:kCAMediaTimingFunctionEaseInEaseOut)
Yoanna Mareva is a Developer in the Telerik iOS Team. She graduated from the Telerik Academy in 2014 to join the team and start adding a great deal of value to the suite of iOS controls. A designer in her heart and developer in her mind, she is a unique product contributor who already has controls like Gauges and Alert for iOS in her arsenal.