在Pickerview中创建一个选中标记 [英] Creating a checkmark inside a Pickerview

查看:44
本文介绍了在Pickerview中创建一个选中标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,我想在该应用程序上由用户在选中的行上创建一个选中标记.

I am developing an application where i want to create a checkmark on the selected row by the user.

例如.

在UITableView中有UITableViewCellAccessoryCheckmark;

In UITableView there is UITableViewCellAccessoryCheckmark;

但是我想知道UIPickerView是否有类似的功能.

But i am wondering is there something similar available for UIPickerView.

是否有任何获得此行为的教程或指针?

Any tutorial or pointer to get this behaviour?

推荐答案

我制作了一个UIPickerView子类,该子类可用于实现此功能.它将触摸事件转发到其父视图,因此可以抑制默认行为,即当条目滚动到中间时会被选中.

I've made a UIPickerView subclass which can be used to implement this functionality. It forwards touch events to its superview and can therefore suppress the default behavior where entries are selected as they scroll past the middle.

pertert 所写,可以通过使用委托方法通过使用UIImageView和UILabel为pickerview的条目创建自定义UIView来实现复选标记:

The checkmark can be implemented by, as pertert writes, creating a custom UIView with an UIImageView and a UILabel for the pickerview's entries via the delegate method:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view

您可以在 Github 上找到包含我的子类的项目.

You can find the project containing my subclass on Github.

这篇关于在Pickerview中创建一个选中标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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