How to change the color of UIPickerView Selector(如何更改 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 选择器的颜色
基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01