如何使用 UIAppearance 设置 UIPickerView 的背景颜色?

s.d*_*.d. 1 objective-c uipickerview ios

我正在使用以下代码行更改UIPickerView整个应用程序的背景颜色,就像应用程序中的主题一样。这没有任何改变。

 [[UIPickerView appearance] setBackgroundColor: [UIColor orangeColor]];
Run Code Online (Sandbox Code Playgroud)

我也尝试了以下行,但这给出了一个看起来很糟糕的奇怪阴影背景。

[[UIView appearanceWhenContainedInInstancesOfClasses:@[[UIPickerView class]]] setBackgroundColor: [UIColor darkGrayColor]];
Run Code Online (Sandbox Code Playgroud)

这是上面一行显示的图像: 在此处输入图片说明

我希望背景颜色是一种纯色。

问题是,如何使用 更改UIPickerView整个应用程序的背景颜色UIAppearance

小智 5

斯威夫特 3.0:

我设法使用这样的方法解决它func numberOfComponents (in pickerView: UIPickerView) -> Int

func numberOfComponents(in pickerView: UIPickerView) -> Int {
    pickerView.backgroundColor = UIColor.blackDark
    return 1
}
Run Code Online (Sandbox Code Playgroud)