sma*_*nja 15 objective-c uipickerview ios ios10 xcode8
我在Xcode 8中构建我的项目.UIPickerView分隔线在iOS 10模拟器和设备中不可见,但在iOS 9.3设备和模拟器上工作正常.我尝试在XIB中调整UIPickerView背景颜色,自动布局和一切可能,但没有任何作用.有人对此有所了解吗?
这是一个包含UIPickerView的自定义视图
-(void)layoutSubviews{
isShown = NO;
[super layoutSubviews];
//self.selectedDic = nil;
self.doneBtn.tintColor = COLOR_DB3535;
self.pickerView.backgroundColor = COLOR_DEDEDE;
self.pickerView.showsSelectionIndicator = YES;
[self.doneBtn setTitle:NSLocalizedString(@"App_Generic_Button_Text_Done", @"")];
}
-(UIView*)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
label.tintColor = [UIColor clearColor];
label.backgroundColor = [UIColor yellowColor];
label.textColor = COLOR_666;
label.font = [FontsManager getFONT_ROBOTO_LIGHT_16];
label.textAlignment = NSTextAlignmentCenter;
NSDictionary *dict = [dataArray objectAtIndex:row];
label.text = @"Test";
return label;
}
Run Code Online (Sandbox Code Playgroud)
小智 35
当我为iOS10重建几个解决方案并在模拟器和设备上部署到iOS10时,我遇到了这个问题.
在我的情况下,我缩小了在初始化期间选择拾取器中的项目的问题.即.我填充了我的选择器,如果我们已经选择了这个属性,那么我预先选择它并且线条存在.我在初始化期间设置挑选器时执行此操作.
所以我的修复,在我的用例中工作,是在没有现有值的情况下选择0元素.
Objective-C的
UIPickerView *pickerView;
...
[pickerView selectRow:0 inComponent:0 animated:YES];
Run Code Online (Sandbox Code Playgroud)
迅速
let pickerView: UIPickerView
...
pickerView.selectRow(0, inComponent: 0, animated: true)
Run Code Online (Sandbox Code Playgroud)
这对我的解决方案很好,因为我在设置上有效地选择了行0.
我没有机会深入了解推理或寻找更清洁的解决方案,但既然我已经解决了我的问题,我想我会在这里分享它,如果可以的话,帮助你们.
小智 12
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 320, 200)];
pickerView.backgroundColor = [UIColor whiteColor];
pickerView.dataSource = self;
pickerView.delegate = self;
[pickerView selectRow:0 inComponent:0 animated:YES];
[self.view addSubview:pickerView];
Run Code Online (Sandbox Code Playgroud)
[pickerView selectRow:0 inComponent:0 animated:YES];在pickerView添加到superView之前添加代码.
我通过以下方式解决了这个问题
self.pickerView.backgroundColor = COLOR_DEDEDE;
self.pickerView.showsSelectionIndicator = YES;
for (UIView *view in self.pickerView.subviews) {
if (view.bounds.size.height < 2.0f && view.backgroundColor == nil) {
view.backgroundColor = PICK_Line_COLOR; // line color
}
}
Run Code Online (Sandbox Code Playgroud)
这个代码在方法之后调用:
[self.view addSubview:pickeView];
最终结果:
它适用于我的项目.希望它对你有所帮助.
我不确定你所说的“分隔线”是什么。我在 iOS 9 中也没有看到“分隔线”。
屏幕截图中唯一缺少的“线条”是选择指示器。您可以通过将选择器视图设置showsSelectionIndicator为 来获取它们YES。但你不应该这样做;默认显示选择指示器。文档说:
在 iOS 7 及更高版本上...始终显示选择指示器
| 归档时间: |
|
| 查看次数: |
8322 次 |
| 最近记录: |