自定义UIPickerView和组件

问题描述 投票:0回答:2

如何创建多选选择器?我有一个项目列表,我希望它们显示在选择器中,并可以选择多重选择它们,并带有复选标记。

我在使用应用程序时看到了这一点,有人可以解释如何实现这一点吗?

我以某种方式部分解决了它,但不知道如何在左侧打勾,这就是我所做的

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
  UILabel *label = (UILabel*) view;
if (label == nil)
{
    label = [[UILabel alloc] init];
}

[label setText:@"Whatever"];    
[label setTextColor:[UIColor whiteColor]];
[label setBackgroundColor:[UIColor blackColor]];
CGSize rowSize = [pickerView rowSizeForComponent:component];
CGRect labelRect = CGRectMake (0, 0, rowSize.width, rowSize.height);
[label setFrame:labelRect];

return label;
}
xcode uipickerview multi-select
2个回答
1
投票

这解决了问题。这是一个可以使用的....

https://github.com/alexleutgoeb/ALPickerView


0
投票

您应该实现 UIPickerViewDelegate 方法,在您的情况下,我相信

pickerView:viewForRow:forComponent:reusingView:
是您需要的方法。

© www.soinside.com 2019 - 2024. All rights reserved.