自定义UIPickerView及组件
如何创建多选选择器?我有一个项目列表,我希望它们显示在选择器中,并可以选择多重选择它们,并带有复选标记。
我在使用应用程序时看到了这一点,有人可以解释如何实现这一点吗?
我以某种方式部分解决了它,但不知道如何在左侧打勾,这就是我所做的
- (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;
}
How can I create a multi select picker? I've a list of items and I want them to show in a picker with the option to multi select them, with checkmarks.
I've seen this while using an app, can somebody explain how this can be achieved?
I somehow solved the it partially, but can't figure out how to put checkmarks on the left, this is what I did
- (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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该实现 UIPickerViewDelegate 方法,在您的情况下,我相信
pickerView:viewForRow:forComponent:reusingView:
是您需要的方法。You should implement UIPickerViewDelegate methods, in your case i believe
pickerView:viewForRow:forComponent:reusingView:
is the one you need.