@@ -87,18 +87,10 @@ class SMRotaryWheel: UIControl {
87
87
let dy = point. y - centre. y
88
88
return ( dx * dx + dy * dy) . squareRoot ( )
89
89
}
90
-
91
- func createView( index: Int ) -> UIView {
92
- let view = UILabel ( frame: CGRect ( x: 0 , y: 0 , width: 100 , height: 40 ) )
93
- view. backgroundColor = . red
94
- view. tag = index
95
- view. text = " \( index) "
96
- return view
97
- }
98
90
99
91
func setup( ) {
100
92
container = UIView ( frame: frame)
101
- guard let container = container, let numberOfSections = numberOfSections else {
93
+ guard let container = container, let delegate = delegate , let numberOfSections = numberOfSections else {
102
94
return
103
95
}
104
96
@@ -107,7 +99,7 @@ class SMRotaryWheel: UIControl {
107
99
108
100
for i in 0 ..< numberOfSections {
109
101
// Create and add view to container
110
- let view = createView ( index : i)
102
+ let view = delegate . viewFor ( tag : i)
111
103
view. layer. anchorPoint = CGPoint ( x: 1.0 , y: 0.5 )
112
104
view. layer. position = CGPoint ( x: container. bounds. size. width / 2.0 , y: container. bounds. size. height / 2.0 )
113
105
view. transform = CGAffineTransform ( rotationAngle: CGFloat ( i) * sectorAngle)
@@ -132,6 +124,6 @@ class SMRotaryWheel: UIControl {
132
124
container. isUserInteractionEnabled = false
133
125
addSubview ( container)
134
126
135
- delegate? . wheelDidChangeValue ( to: currentSector)
127
+ delegate. wheelDidChangeValue ( to: currentSector)
136
128
}
137
129
}
0 commit comments