Skip to content

Commit ce122c2

Browse files
committed
Split out view creation
1 parent ec5e583 commit ce122c2

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

SMRotaryWheel.swift

+9-4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ class SMRotaryWheel: UIControl {
8888
return (dx * dx + dy * dy).squareRoot()
8989
}
9090

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+
9199
func setup() {
92100
container = UIView(frame: frame)
93101
guard let container = container, let numberOfSections = numberOfSections else {
@@ -99,13 +107,10 @@ class SMRotaryWheel: UIControl {
99107

100108
for i in 0..<numberOfSections {
101109
// Create and add view to container
102-
let view = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 40))
103-
view.backgroundColor = .red
104-
view.text = "\(i)"
110+
let view = createView(index: i)
105111
view.layer.anchorPoint = CGPoint(x: 1.0, y: 0.5)
106112
view.layer.position = CGPoint(x: container.bounds.size.width / 2.0, y: container.bounds.size.height / 2.0)
107113
view.transform = CGAffineTransform(rotationAngle: CGFloat(i) * sectorAngle)
108-
view.tag = i
109114

110115
container.addSubview(view)
111116

0 commit comments

Comments
 (0)