Created
May 27, 2015 16:07
-
-
Save loiclefloch/6382c206ffff8f90083d to your computer and use it in GitHub Desktop.
Horizontal Number Picker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate { | |
@IBOutlet weak var dividerPickerViewContainer: UIView! | |
var dividerPickerView: UIPickerView = UIPickerView() | |
override func viewDidLoad() { | |
// dividerPicker | |
self.dividerPickerView.delegate = self | |
self.dividerPickerView.dataSource = self | |
self.dividerPickerView.showsSelectionIndicator = false | |
self.dividerPickerView.frame = CGRectMake(65, -70, 30, 200) | |
self.dividerPickerView.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI / 2)) | |
self.dividerPickerViewContainer.addSubview(self.dividerPickerView) | |
} | |
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { | |
if pickerView == self.dividerPickerView { | |
return 99; | |
} | |
else { | |
return 0; | |
} | |
} | |
func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, | |
reusingView view: UIView!) -> UIView { | |
var label: UILabel = UILabel(frame: CGRectMake(0, 0, 30, 100)) | |
label.text = String(format:"%ld", row + 1) | |
label.opaque = false; | |
label.textAlignment = NSTextAlignment.Center; | |
label.backgroundColor = UIColor.clearColor() | |
label.textColor = UIColor.whiteColor(); | |
label.transform = CGAffineTransformMakeRotation(CGFloat(M_PI / 2)); | |
return label; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment