How can I get a check mark beside UIPickerView labels?

心不动则不痛 提交于 2019-11-30 07:26:21

You need to implement -pickerView:viewForRow:forComponent:reusingView: from the UIPickerViewDelegate.

You have to create a view, that contains a UIButton with the checkmark image, and return it from -pickerView:viewForRow:forComponent:reusingView:

Here is some official sample code for customizing UIPicker view: http://developer.apple.com/library/ios/#samplecode/UICatalog/Introduction/Intro.html

In particular, refer to classes PickerViewController.{h, m} , CustomPickerDataSource.{h, m} and CustomView.{h, m} in the example. You can create a similar custom UIPickerView with a tick image which gets displayed only to the left for the selected item and change the text color of selected item. Also, remember to set myPickerView.showsSelectionIndicator = NO; to remove the semi-transparent bar above the selected item.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!