UIPickerView选择指示器在iOS10中不可见 [英] UIPickerView selection indicator not visible in iOS10

查看:288
本文介绍了UIPickerView选择指示器在iOS10中不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Xcode 8中构建我的项目.UIPickerView分隔线在iOS 10模拟器和设备中不可见,但在iOS 9.3设备和模拟器中可以正常工作.我试图调整UIPickerView的背景色,自动布局以及XIB中的所有可能设置,但没有任何效果.有人对此有想法吗?

I build my project in Xcode 8. UIPickerView separator lines are not visible in iOS 10 simulator and the devices, but works fine on iOS 9.3 devices and simulator. I tried to adjust the UIPickerView back ground color, auto layouts and everything possible in the XIB, but nothing works. Anyone have an idea on this?

这是一个包含UIPickerView的自定义视图

This is a custom view which contains a 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;
}

推荐答案

当我为iOS10重建了几个解决方案并在模拟器和设备上都部署到iOS10时,我遇到了这个确切的问题.

I had this exact issue when I rebuilt a couple of solutions for iOS10 and deployed to iOS10 on both simulators and devices.

在我的案例中,我将问题缩小为在初始化期间在选择器中选择一个项目. IE.我填充了选择器,如果我们已经对该属性进行了选择,那么我将对其进行预选择,并显示行.我在初始化选择器时进行此设置.

I narrowed the problem in my case to be down to selecting an item in the picker during initialisation. ie. I populate my picker and if we have already got a selection for this property then I preselect it and the lines are present. I do this during the initialisation when I set up my picker.

因此,在我的用例中有效的解决方法是在没有现有值的情况下选择0元素.

So my fix, which worked in my use case, was to select the 0 element in the case of no existing value.

Objective-C

UIPickerView *pickerView;

...

[pickerView selectRow:0 inComponent:0 animated:YES];

快速

let pickerView: UIPickerView

...

pickerView.selectRow(0, inComponent: 0, animated: true)

这对我的解决方案很好,因为我在设置时有效地选择了零行.

This was fine for my solution since I effectively select row zero on setup.

我没有机会深入研究推理或寻找更清洁的解决方案,但是由于我已经解决了我的问题,所以我想在这里分享它,如果可以的话,可以帮助您.

I haven't had chance to dig into the reasoning or look for a cleaner solution, but since I've solved my problem I thought I'd share it here to help you all out if I can.

这篇关于UIPickerView选择指示器在iOS10中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆