Skip to content

Instantly share code, notes, and snippets.

@SubZane
Created May 13, 2019 15:31
Show Gist options
  • Save SubZane/73ea7df66d0ae397973791ffd445a41e to your computer and use it in GitHub Desktop.
Save SubZane/73ea7df66d0ae397973791ffd445a41e to your computer and use it in GitHub Desktop.
class AddSetViewController: UIViewController {
@IBOutlet weak var RepsPickerView: UIPickerView!
var rotationAngle: CGFloat!
override func viewDidLoad() {
super.viewDidLoad()
rotationAngle = -90 * (.pi / 180)
let y = RepsPickerView.frame.origin.y
RepsPickerView.transform = CGAffineTransform(rotationAngle: rotationAngle)
RepsPickerView.frame = CGRect(x: -100, y: y, width: view.frame.width + 200, height: 80)
}
}
class RepsPickerView: UIPickerView, UIPickerViewDelegate, UIPickerViewDataSource {
private var reps = Array(0...100)
private var selectedRep: Int!
override init(frame: CGRect) {
super.init(frame: frame)
self.commonSetup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.commonSetup()
}
func commonSetup() {
self.delegate = self
self.dataSource = self
}
func onSelected() -> Int {
return self.selectedRep
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return 100
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
self.selectedRep = reps[row]
}
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let view = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
let label = UILabel(frame: CGRect(x: 0, y: 10, width: 50, height: 50))
label.text = String(reps[row])
label.textAlignment = .center
label.font = UIFont.systemFont(ofSize: 16, weight: .semibold)
view.addSubview(label)
view.transform = CGAffineTransform(rotationAngle: (90 * .pi/180))
return view
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment