且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何更改 UIPickerView 选择器的颜色

更新时间:2023-12-04 12:34:52

我想你是在处理 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.