如何使用SDK 7在iOS 7上设置UIPickerView的背景颜色?
如何使用SDK 7 在iOS 7上设置UIPickerView
的背景颜色,并在iOS 5和iOS 6上使用标准select器? 它在iOS 7上默认是透明的。
有什么问题:
[picker setBackgroundColor:[UIColor whiteColor]];
我假设你有一个引用select器视图,如果你正在调用它,它是UIView的一个子类,所以backgroundColor
是一个有效的属性…
我想写它作为评论,但它会很难阅读:) Sooo ….
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view { UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 44)]; // your frame, so picker gets "colored" label.backgroundColor = [UIColor lightGrayColor]; label.textColor = [UIColor blackColor]; label.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:18]; label.text = [NSString stringWithFormat:@"%d",row]; return label; }
也不一定只是标签,我想你也可以在其中插入其他子视图…就我所知,它可以在iOS7上运行
我用UIPickerView
在代码中添加了UIView
:
CGRect framePickerView = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 216); pickerView = [[[UIView alloc] initWithFrame:framePickerView] autorelease]; pickerView.backgroundColor = [UIColor whiteColor]; [self.view addSubview:pickerView]; [pickerView addSubview:picker];
代码是:
[self.view addSubview:picker];
这在iOS 7.1中适用于我:
[[UIPickerView appearance] setBackgroundColor:[UIColor whiteColor];
这改变了所有采摘者的颜色。 如果您只希望在iOS 7的设备上运行,可以在其中添加条件。
对于任何人在迅速工作,并可能使用多个采集器:
pickerView1.backgroundColor = UIColor.darkGrayColor() pickerView2.backgroundColor = UIColor.greenColor()
Xcode 7.3