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 :)