Dmi*_*try 16 iphone uipickerview ios ios7
如何使用SDK 7 UIPickerView
在iOS 7上设置背景颜色,并在iOS 5和6上使用标准选择器?默认情况下,它在iOS 7上是透明的.
Jes*_*sse 40
有什么不对:
[picker setBackgroundColor:[UIColor whiteColor]];
Run Code Online (Sandbox Code Playgroud)
如果你正在调用它,我假设你有一个对picker视图的引用,它是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;
}
Run Code Online (Sandbox Code Playgroud)
它也不一定只是标签,我想你也可以在那里插入其他子视图......据我所知,它适用于iOS7
在iOS 7.1中,这对我有用:
[[UIPickerView appearance] setBackgroundColor:[UIColor whiteColor];
Run Code Online (Sandbox Code Playgroud)
这会改变所有拣货员的颜色.如果您只希望在iOS 7设备上运行,则可以在其周围添加条件.
我加入UIView
下UIPickerView
的代码:
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];
Run Code Online (Sandbox Code Playgroud)
而是代码:
[self.view addSubview:picker];
Run Code Online (Sandbox Code Playgroud)
即使我设置了 UIPickerView.backgorundColor
,但我的背景颜色很奇怪。
删除以下行修复了问题:
UITextField.keyboardAppearance = .dark
Run Code Online (Sandbox Code Playgroud)
或者只是重置keyboardAppearance
回默认值,如下所示:
UITextField.keyboardAppearance = .default
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
33755 次 |
最近记录: |