I see many solutions out there for the UIPickerView font size, but it seems they are all based on text based arrays and / or require a UIViewController.
I am using an Int Array within a UITableViewCell and cannot seem to find something that will work with what I am trying to accomplish.
Here is the code:
import UIKit
class AirTemperatureTableViewCell: UITableViewCell, UIPickerViewDelegate, UIPickerViewDataSource
{
let numberOfComponents: Int = 2
let temperatureComponentRows: Int = 501
let temperatureSymbolComponentRows: Int = 2
let Fahrenheit: String = "F"
let Celsius: String = "C"
let minDegrees = -250
let maxDegrees = 250
private var degrees: Array<Int> = [Int]()
var temperature: Int = 30 // our default temperature
var temperatureType: String = "C" // our default type is Celsius
#IBOutlet var airTemperaturePicker: UIPickerView!
override func awakeFromNib()
{
super.awakeFromNib()
for i in self.minDegrees ..< self.maxDegrees+1
{
self.degrees.append(i)
}
self.airTemperaturePicker.selectRow(280, inComponent: 0, animated: true)
}
override func setSelected(selected: Bool, animated: Bool)
{
super.setSelected(selected, animated: animated)
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int
{
return self.numberOfComponents
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int
{
if component == 0
{
return self.temperatureComponentRows
}
else
{
return self.temperatureSymbolComponentRows
}
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String?
{
//
// If we are component 0, the degrees, return the value for the given row.
//
if component == 0
{
return String(self.degrees[row])
}
else
{
if row == 0
{
return self.Celsius
}
else
{
return self.Fahrenheit
}
}
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
}
}
any help would be appreciated.
You can use a UILabel with the viewForRow method of the UIPickerViewDataSource. You can then configure it with all the regular label options incl. setting font size, color, etc.:
// goes in lieu of titleForRow if customization is desired
func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView?) -> UIView {
let pickerLabel = UILabel()
if component == 0 {
pickerLabel.textColor = .darkGrayColor()
pickerLabel.textAlignment = .Center
pickerLabel.text = String(self.degrees[row])
pickerLabel.font = UIFont(name:"Helvetica", size: 28)
} else {
pickerLabel.textColor = .redColor()
pickerLabel.textAlignment = .Center
pickerLabel.font = UIFont(name:"Helvetica", size: 28)
if row == 0 {
pickerLabel.text = self.Celsius
} else {
pickerLabel.text = self.Fahrenheit
}
}
return pickerLabel
}
You should use the UIPickerViewDelegate function viewForRow inside your UITableViewCell subclass like so:
func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView?) -> UIView {
let view = UIView(frame: picker.frame)
let label = UILabel(frame: picker.frame)
label.textAlignment = .Center
label.text = String(degrees[row])
label.font = UIFont(name: "Arial", size: 15)
label.adjustsFontSizeToFitWidth = true
view.addSubview(label)
return view
}
picker is an #IBOutlet for your UIPickerView in your UITableView subclass set using either the prototype cell or external nib and control-drag. Also, make sure to set the picker's delegate and dataSource properties inside awakeFromNib.
override func awakeFromNib() {
super.awakeFromNib()
picker.dataSource = self
picker.delegate = self
//Your Code Below
}
This should make a cell width pickerView with a UILabel of your font choice.
Related
should look like this
In pickerView i want to change title font size, as I scroll the selected row title font will be of high font size and above selected title font size will be decreasing and same for below selected row.
import UIKit
Vc:
class ViewController: UIViewController {
#IBOutlet weak var pickerView: UIPickerView!
var pickerTitle = ["10:00","10:00","10:00","10:00","10:00","10:00","10:00","10:00","10:00","10:00","10:00","10:00","10:00","10:00","10:00","10:00","10:00","10:00","10:00","10:00","10:00","10:00","10:00","10:00"]. // time to display in pickerView
var fontSize = [4,6,8,10,12,14,16,18,20,22,24,26,24,22,20,18,16,14,12,10,8,6,4,2] // font size when view is loaded and when I scroll I need to change the font size so this won't work I guess
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
pickerView.delegate = self
pickerView.dataSource = self
pickerView.reloadAllComponents()
pickerView.selectRow(11, inComponent: 0, animated: true)
}
}
datasource and delete for pickerView:
extension ViewController: UIPickerViewDelegate,UIPickerViewDataSource {
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerTitle.count
}
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let pickerLabel = UILabel()
let titleData = pickerTitle[row]
let myTitle = NSAttributedString(string: titleData, attributes: [NSAttributedString.Key.font:UIFont(name: "Georgia", size: CGFloat(fontSize[row]))!,NSAttributedString.Key.foregroundColor:UIColor.black])
pickerLabel.attributedText = myTitle
pickerLabel.textAlignment = .right
return pickerLabel
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
for var i in 0...row{
print(i)
}
for var i in row..<pickerTitle.count{
print(i)
}
pickerView.reloadAllComponents()
}
}
Not sure what your requirements are, and what you're doing in the code.
But what I could understand is that you want an increased font size for selected title in pickerView, and the rest unselected titles stays smaller; then here is the code:
(if not, please clarify further)
extension ViewController: UIPickerViewDelegate,UIPickerViewDataSource {
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerTitle.count
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
pickerView.reloadAllComponents()
}
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
var label = view as! UILabel?
if label == nil {
label = UILabel()
label?.textAlignment = .center
}
switch component {
case 0:
label?.text = pickerTitle[row]
if(pickerView.selectedRow(inComponent: 0) == row){
label?.font = UIFont(name: "Georgia", size: 26)
}
return label!
default:
return label!
}
}
}
I have to change the color of the selected row in a UIPickerView.
I did managed to change the color, i know that the question already have several replies, anyway those do not satisfy me: with those implementation, the animation of the pickerview is glitchy and i don't like it.
This is the code of the current solution
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
var label: UILabel
if view == nil {
label = UILabel()
} else if view is UILabel {
label = view as! UILabel
} else {
label = UILabel()
}
let title: NSAttributedString
if self.model?.selectedValue == row {
title = UIPickerView.attributedString(with: .selectedRow, text: "\(model?.years[row] ?? 0)")
} else {
title = UIPickerView.attributedString(with: .unselectedRow, text: "\(model?.years[row] ?? 0)")
}
label.attributedText = title
return label
}
And when the user scrolls, I reload the components.
But as you can see in the images below, when a user scroll, the green field moves and there is a fraction of seconds in which the green label is below the selector indicator and the selected row is black.
What I'd like to have is that everything inside the selector indicator is green while what outside keeps the default shades of grey.
How can I implement this?
You should use attributedTitleForRow for this instead, no need to create your own label with an NSAttributedString. In your didSelectRow your reload all your components to be able to reset all colors and set the new selected one to green.
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let color = (row == pickerView.selectedRow(inComponent: component)) ? UIColor.green : UIColor.black
return NSAttributedString(string: self.model[row], attributes: [NSForegroundColorAttributeName: color])
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
pickerView.reloadAllComponents()
}
You can simply use this code
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let label = view as? UILabel ?? UILabel()
if pickerView.selectedRow(inComponent: component) == row {
label.backgroundColor = UIColor.green
label.frame = CGRect(x: 0, y: 0, width: 36, height: 36)
label.layer.cornerRadius = 18
label.layer.masksToBounds = true
label.textColor = .white
label.text = String(numbers[row])
label.textAlignment = .center
}else {
label.layer.cornerRadius = 25
label.frame = CGRect(x: 0, y: 0, width: 36, height: 36)
label.layer.cornerRadius = 18
label.layer.masksToBounds = true
label.textColor = .white
label.text = String(numbers[row])
label.textAlignment = .center
}
return label
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
pickerView.reloadAllComponents()
}
Better effects with performance a little bad.
extension ViewController: UIPickerViewDelegate{
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let info = BeatScalar.generalRates[row]
let general = GeneralRateItem(info.cn, info.ita, info.val)
// gray every row
general.unselected()
decorateView(pickerView, row: row)
return general
}
// Here is the logic
func decorateView(_ picker: UIPickerView, row: Int){
var frame = picker.frame
frame.origin.y = frame.origin.y + frame.size.height * 0.42
frame.size.height = frame.size.height * 0.16
let mini = max(row-1, 0)
// 19 is total number
let maxi = min(18, row+1)
for i in mini...maxi{
if i != row, let item = picker.view(forRow: i, forComponent: 0) as? GeneralRateItem{
let f = item.convert(item.frame, to: picker)
if frame.intersects(f) == false{
// highlight the center row
item.selected()
}
}
}
}
func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
return 44
}
}
extension ViewController: UIPickerViewDataSource{
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { // 19 is total number
return 19
}
}
I'm trying to place 2 pick views in one view controller. I tried setting different tags for them. But both views have the "choices" array in them. I control-dragged both and set to data source and delegate. I also tried the below code. Thanks in advance.
import Foundation
import UIKit
class SecondViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
var model = Model()
#IBOutlet weak var hoursTakenText: UITextField!
#IBOutlet weak var PickerView2: UIPickerView!
#IBOutlet weak var pickerView1: UIPickerView!
let choices2 = ["0","0.7","1.0"]
let choices: [String] = (1...90).map { String($0)}
#IBAction func hoursTaken(_ sender: Any) {
subView.isHidden = false
}
#IBOutlet weak var subView: UIView!
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if pickerView == pickerView1 {
return choices[row]}
else {
return choices2[row]
}
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if pickerView == pickerView1 {
return choices.count}
else{
return choices2.count
}
}
//choices[row]: [String] = (1...10).map { "Option " + String(format: "%2d", $0)}
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let label = (view as? UILabel) ?? UILabel()
label.font = UIFont(name: "Verdana", size: 15)
//label.textColor = .blue
label.textAlignment = .center
//label.font = UIFont.systemFont(ofSize: 20)
label.text = choices[row]
return label
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
let hourstaken = Double(choices[row])
print(hourstaken!)
var stuDent: Student
if pickerView == pickerView1 {
print(choices[row])
stuDent = Student(hoursTaken: hourstaken!)
model.student.append(stuDent)
}
subView.isHidden = true
hoursTakenText.text = choices[row]
print("hello")
}
override func viewDidLoad() {
//pickerViewBack.isHidden = true
super.viewDidLoad()
subView.isHidden = true
}
}
You are choosing between the two picker views in your implementation of numberOfRowsInComponent but not in your implementation of viewForRow. Your viewForRow always refers to choices[row] and sets the label's text from that. Therefore choices is displayed in both picker views.
You didn't check which UIPickerView you are setting the rows for in viewForRow, so you set the same data for both.
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let label = (view as? UILabel) ?? UILabel()
label.font = UIFont(name: "Verdana", size: 15)
label.textAlignment = .center
if pickerView == pickerView1 {
label.text = choices[row]
} else {
label.text = choices2[row]
}
return label
}
You can use tags to do that
var pickerTags: Int = -1
func pickersCon(){
self.pickerView1.tag = 1
self.pickerView1.delegate = self
self.pickerView2.tag = 2
self.pickerView2.delegate = self
}
And in your pickerView methods you may do the following
For example
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if pickerView.tag == 1 {
return choices[row]}
else if pickerView.tag == 2 {
return choices2[row]
}
}
recently I need a solution to show a present-like pickerView for choosing data for some property, like profile.
what I did is
1, create a empty project
2, create a AViewController which will be used as subview. And I add a pickerView and a navigation bar into that view and adjust the view's height to around 260.
3, write code in that AViewController's class.
class APickerViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
#IBOutlet weak var pickerView:UIPickerView!
let dataList = [["a","b","c","d"]]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
//pickerView.dataSource = self
//pickerView.delegate = self
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return dataList.count
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return dataList[component].count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return dataList[component][row]
}
4, write code in Main ViewController to add the AViewController's View as subview.
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let pickerViewController = storyboard?.instantiateViewController(withIdentifier: String(APickerViewController.self)) as! APickerViewController
self.view.addSubview(pickerViewController.view)
self.view.bringSubview(toFront: pickerViewController.view)
pickerViewController.view.frame = CGRect(x: 0, y: self.view.frame.height - 300, width: self.view.frame.width, height: 300)
}
and also one question here actually I'm not that sure the difference.
A:
let pickerViewController = storyboard?.instantiateViewController(withIdentifier: String(APickerViewController.self)) as! APickerViewController
B:
let pickerViewController = APickerViewController()
What's the different of A and B ? If I do some #IBOutlet settings by Interface Builder will be affected or what ?
5, go and ... get weired ...
the function
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return dataList[component].count
}
sometime's get called many times and sometimes not get called.
and the data was not show in pickerView and sometimes only show row 1,2 and no others and if I flick up or down those 1,2 row data disappeared.
if anyone have a better solution of using pickerView as option popup window ?
Help.
Thanks
class EditViewController: UIViewController,UITextFieldDelegate,UIPickerViewDelegate{
var picker : UIPickerView = UIPickerView()
var toolBar : UIToolbar = UIToolbar()
#IBOutlet var txtFieldState: UITextField!
var stateArray = ["Andaman & Nicobar Island","Andhra Pradesh","Arunachal Pradesh","Assam","Bihar","Chandigarh","Chhattisgarh","Dadra & Nagar"]
override func viewDidLoad() {
super.viewDidLoad()
txtFieldState.delegate = self
}
func textFieldDidBeginEditing(textField: UITextField) {
if textField == txtFieldState{
txtFieldState.inputView = picker
txtFieldState.inputAccessoryView = toolBar
self.configurePicker()
}
}
func configurePicker()
{
picker.alpha = 1.0
picker.backgroundColor = UIColor(red:241/255.0, green:241/255.0, blue:241/255.0, alpha: 1.0)
picker.showsSelectionIndicator = true
picker.delegate = self
picker.selectedRowInComponent(0)
let screenRect = self.view.frame
let pickerSize = picker.sizeThatFits(CGSizeZero)
let x = screenRect.origin.x + (screenRect.size.width / 2) - (pickerSize.width / 2)
let pickerRect = CGRectMake(x,
screenRect.origin.y + (screenRect.size.height) - (pickerSize.height),
pickerSize.width,
pickerSize.height)
picker.frame = pickerRect
let toolbarSize = toolBar.sizeThatFits(CGSizeZero)
toolBar.frame = CGRectMake(x,pickerRect.origin.y, // right under the picker
pickerSize.width, // make them the same width
toolbarSize.height)
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int){
dropState = row
txtFieldState.text = "\(stateArray[row])"
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String?
{
return stateArray[row]
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int
{
return stateArray.count
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int
{
return 1
}
}
I need to implement UIPickerView like this:
But default implementation gives this:
I used this UIPickerDatasourse method:
func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView?) -> UIView {
var pickerLabel = view as? UILabel;
if (pickerLabel == nil)
{
pickerLabel = UILabel()
pickerLabel?.textAlignment = NSTextAlignment.Center
}
pickerLabel?.attributedText = help_getAttributedStringForWalletByAmount(ApiManager.sharedInstance.userService_currentUser!.arrayCurrencyAccounts[row].balance, currency: EnumCurrency(rawValue: ApiManager.sharedInstance.userService_currentUser!.arrayCurrencyAccounts[row].currency))
pickerLabel?.sizeToFit()
return pickerLabel!;
}
Is it possible to make bigger scaling? Or may be is there any other workaround ?
You can try like,
func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let color = (row == pickerView.selectedRowInComponent(component)) ? UIColor.orangeColor() : UIColor.blackColor()
return NSAttributedString(string: colors[row], attributes: [NSForegroundColorAttributeName: color])
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
pickerView.reloadAllComponents()
}
It is changing color, you try fontsize in attributed string.
Update:
refer this answer as mentioned in it don't implement titleFoRrow at all only implement viewForRow. and setup label with desired font size.
Hope this will help :)
Lion's answer actually works, but it's not smooth, so when you select another row, it's not user friendly (I think it works with colours, but for different fonts it's not the best solution). So I decided to affine transforms. Here is the code:
// MARK: - Picker View Help
func pickerViewHelp_afterRowWasSelected(row: Int) {
let accountSelected = ApiManager.sharedInstance.userService_currentUser!.arrayCurrencyAccounts[row]
// save ID of this currency account in NSDefaults
DefaultsManager.sharedInstance.getDefaultsForSharingBetweenExtensions().setValue(accountSelected.id, forKey: kNSDefaults_mainCurrencyAccountID)
DefaultsManager.sharedInstance.getDefaultsForSharingBetweenExtensions().synchronize()
// reload scales
delay(0) { [weak self] in
self?.pickerViewHelp_updateFontsForAllRows(self!.pickerViewAccounts, selectedIndex: row)
}
}
func pickerViewHelp_updateFontsForAllRows(pickerView: UIPickerView, selectedIndex: Int) {
if pickerViewHelp_rowWasChangedBeforeReloadingPicker { // we changed the row
// remove prev animation
for i in 0..<pickerView.numberOfRowsInComponent(0) {
let pickerLabel = pickerViewHelp_dictOfViewsInPicker[i] as? UILabel
pickerLabel?.layer.removeAllAnimations()
}
// start new animation
for i in 0..<pickerView.numberOfRowsInComponent(0) {
UIView.animateWithDuration(0.3) { [weak self] in
let scale: CGFloat = (i == selectedIndex) ? 1 : 0.5
// let pickerLabel = pickerView.viewForRow(i, forComponent: 0) as? UILabel
let pickerLabel = self?.pickerViewHelp_dictOfViewsInPicker[i] as? UILabel
var transform = CATransform3DIdentity
transform = CATransform3DScale(transform, scale, scale, 1.01)
pickerLabel?.layer.transform = transform
}
}
}
else if pickerViewHelp_previouslySelectedRow == -1 { // first setup of the picker or we selected the same row
// remove prev animation
for i in 0..<pickerView.numberOfRowsInComponent(0) {
let pickerLabel = pickerViewHelp_dictOfViewsInPicker[i] as? UILabel
pickerLabel?.layer.removeAllAnimations()
}
// without animation
for i in 0..<pickerView.numberOfRowsInComponent(0) {
let scale: CGFloat = (i == selectedIndex) ? 1 : 0.5
let pickerLabel = pickerViewHelp_dictOfViewsInPicker[i] as? UILabel
var transform = CATransform3DIdentity
transform = CATransform3DScale(transform, scale, scale, 1.01)
pickerLabel?.layer.transform = transform
}
}
else { // repeat 1 if (for now I want leave in like this, because if smth is wrong, I will need to change it separately
// remove prev animation
for i in 0..<pickerView.numberOfRowsInComponent(0) {
let pickerLabel = pickerViewHelp_dictOfViewsInPicker[i] as? UILabel
pickerLabel?.layer.removeAllAnimations()
}
// start new animation
for i in 0..<pickerView.numberOfRowsInComponent(0) {
UIView.animateWithDuration(0.3) { [weak self] in
let scale: CGFloat = (i == selectedIndex) ? 1 : 0.5
// let pickerLabel = pickerView.viewForRow(i, forComponent: 0) as? UILabel
let pickerLabel = self?.pickerViewHelp_dictOfViewsInPicker[i] as? UILabel
var transform = CATransform3DIdentity
transform = CATransform3DScale(transform, scale, scale, 1.01)
pickerLabel?.layer.transform = transform
}
}
}
}
// MARK: - Picker view
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if ApiManager.sharedInstance.userService_currentUser?.arrayCurrencyAccounts == nil { // no account
return 0
}
else {
let count = ApiManager.sharedInstance.userService_currentUser!.arrayCurrencyAccounts.count
return count
}
}
var pickerViewHelp_rowWasChangedBeforeReloadingPicker = false
var pickerViewHelp_dictOfViewsInPicker = [Int: UIView]()
func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView?) -> UIView {
var pickerLabel = view as? UILabel;
if (pickerLabel == nil)
{
pickerLabel = UILabel()
pickerLabel?.textAlignment = NSTextAlignment.Center
}
pickerLabel?.attributedText = help_getAttributedStringForWalletByAmount(ApiManager.sharedInstance.userService_currentUser!.arrayCurrencyAccounts[row].balance, currency: EnumCurrency(rawValue: ApiManager.sharedInstance.userService_currentUser!.arrayCurrencyAccounts[row].currency), scaleOfText: 1)
pickerViewHelp_dictOfViewsInPicker[row] = pickerLabel
return pickerLabel!;
}
func pickerView(pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
return 60
}
var pickerViewHelp_previouslySelectedRow = -1
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if pickerViewHelp_previouslySelectedRow != row {
pickerViewHelp_rowWasChangedBeforeReloadingPicker = true
}
else {
pickerViewHelp_rowWasChangedBeforeReloadingPicker = false
}
pickerViewHelp_previouslySelectedRow = row
pickerView.selectRow(row, inComponent: 0, animated: false) // because otherwise sometimes it stops between cells in the picker
if pickerViewHelp_rowWasChangedBeforeReloadingPicker {
// print("reload all components")
pickerView.reloadAllComponents()
}
pickerViewHelp_afterRowWasSelected(row)
}
It's not ideal either, but our designer liked it so we decided to use this way