The following swift code will give show you how to obtain the width from the first column plus how to set up all the columns’ label
func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView!) -> UIView { // Display the first column's width // The value 0 is to point to the first column regardless if you have one or multiple columns NSLog("Width: \(pickerView.rowSizeForComponent(0).width)") let pickerLabel : UILabel = UILabel() // pickerViewLabelTextForComponentRow is a custom made function to obtain what text will go in each row pickerLabel.text = pickerViewLabelTextForComponentRow(component, row: row) pickerLabel.textAlignment = NSTextAlignment.Center pickerLabel.textColor = UIColor.blackColor() pickerLabel.font = UIFont.boldSystemFontOfSize(13.0) pickerLabel.backgroundColor = UIColor.lightGrayColor() // If you wish to set up the labels individually in each column, use the value of the parameter component with a control condition such as if or switch return pickerLabel }
© 2015, Alejandro G. Carlstein Ramos Mejia. All rights reserved.