如何更改 UIPickerView 选择器的颜色

How to change the color of UIPickerView Selector(如何更改 UIPickerView 选择器的颜色)

本文介绍了如何更改 UIPickerView 选择器的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UIPicker,我想更改选择器的颜色.是否可以更改选择器的颜色?

I am having a UIPicker, I want to change the color of the selector. Is it possible to change the color of the selector?

推荐答案

我想你是在处理 iPhone SDK 吧?可能有一些其他框架使用这个名称,所以也许你可以添加你的标签来包括 uikit、cocoa-touch 或其他东西.

I suppose you're dealing with the iPhone SDK? There may be some other frameworks which uses this name, so maybe you can add your tags to include uikit, cocoa-touch or something.

无论如何,您可以将 UIPickerView 实例的 showsSelectionIndicator 设置为 NO,从而隐藏选择器.然后你就可以创建一个新的视图,调整后的选择样式,并将其添加到 UIPickerView 上方的 superview 中.

Anyway, you can set showsSelectionIndicator of the UIPickerView instance to NO, so it hides the selector. Then you can create a new view with the adjusted selection style, and add it to the superview above the UIPickerView.

// Some sample code, but you can do this in IB if you want to
_pickerView = [[UIPickerView alloc] init];
_pickerView.showsSelectionIndicator = NO;
[_pickerView sizeToFit];
[self.view addSubview:_pickerView];

UIImage *selectorImage = [UIImage imageNamed:@"selectorImage.png"]; // You have to make it strechable, probably
UIView *customSelector = [[UIImageView alloc] initWithImage:selectorImage];
customSelector.frame = CGRectZero; // Whatever rect to match the UIImagePicker
[self.view addSubview:customSelector];
[customSelector release];

破解 UI 元素本身需要更多的工作,而且这也必须有效.

Hacking the UI Element itself will take much more work, and this has to work as well.

这篇关于如何更改 UIPickerView 选择器的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何更改 UIPickerView 选择器的颜色

基础教程推荐