Eureka: PickerInlineRow customization

Created on 5 Dec 2016  路  10Comments  路  Source: xmartlabs/Eureka

Hello,
do you have any idea on how to customize the UIPickerView inside the PickerInlineRow without subclassing everything?

My goal is to change font color to white.

Thanks in advance

PickerInlineRow PickerRow feature request

Most helpful comment

The pull request mentioned above is now merged; this will allow configuration of the picker to be black with white text (for example) as follows:

PickerInlineRow<String>.InlineRow.defaultCellUpdate = { cell, _ in
    cell.backgroundColor = .black
    cell.pickerTextAttributes = [.foregroundColor: UIColor.white]
}

All 10 comments

Unfortunately there is no an elegant way to customize it. According to the apple documentation and StackOverflow we should implement a UIPickerView delegate method to customize how it looks like.

http://stackoverflow.com/questions/28077130/change-uipickerview-font-size-for-different-column

let me see if we can make that easier than subclassing.

Any updates on this? I'm building an app with a "dark" theme and the PickerInlineRow is the only field left to customize :(

The only way to customize UIPickers seems to be through setting up a delegate for the Controller. However, this has the issue of not updating the Form once this delegate has been changed. Is there any updates on altering the Picker attributes without delegation?

Hey there, I had the same issue where I need to change background and text color of the picker view. After so many unsuccessful attempts I had to unlock library and add this line in PickerCell;

public var pickerTextFontAndColor: (UIFont, UIColor) = (UIFont(), .black)

then I changed this pickerView delegate method;

open func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return pickerRow?.displayValueFor?(pickerRow?.options[row])
}

to;

open func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let title = pickerRow?.displayValueFor?(pickerRow?.options[row]) ?? ""
return NSAttributedString(string: title, attributes: [NSAttributedStringKey.font: self.pickerTextFontAndColor.0, NSAttributedStringKey.foregroundColor: self.pickerTextFontAndColor.1])
}

After that I call PickerInlineRow defaultCellSetup like this;

PickerInlineRow<String>.InlineRow.defaultCellSetup = {cell, row in
cell.picker.backgroundColor = GlobalAppearance.backgroundColor
cell.pickerTextFontAndColor = (UIFont(), GlobalAppearance.textColor)
}

and everything works as expected.

I just raised a pull request (#1595) which - by coincidence - almost exactly copies your approach, @YasinMaySiber

It just allows specification of a UIColor which is used in the attributed string; I could extend the PR to font specification also if necessary.

The pull request mentioned above is now merged; this will allow configuration of the picker to be black with white text (for example) as follows:

PickerInlineRow<String>.InlineRow.defaultCellUpdate = { cell, _ in
    cell.backgroundColor = .black
    cell.pickerTextAttributes = [.foregroundColor: UIColor.white]
}

Closing the issue as the fix has been merged. If there is another issue please open a new one.

Hi, I'm trying to undo how dark mode sets eureka to the opposite colors to what I want. I have been able to change some of the colors so that it appears normal in dark mode. I have spent a long time on this and I have been unable to check the text of the picker view options to black. Any advice for how to undo Dark Mode for the picker row?

Xcode doesn't let me do this:
PickerInlineRow.InlineRow.defaultCellSetup

@michaeldebo Are you using Eureka 5.1.0 which supports dark mode?

Was this page helpful?
0 / 5 - 0 ratings