How can I get a check mark beside UIPickerView labels?

浪子不回头ぞ 提交于 2019-12-18 12:33:26

问题


The UIPickerView that appears in Safari has a check mark beside the current choice. Is there a built-in way to get this, or do I have to program it up myself? If I do have to create it, can anyone point me to some code to do this? Thanks


回答1:


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:




回答2:


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.



来源:https://stackoverflow.com/questions/4448329/how-can-i-get-a-check-mark-beside-uipickerview-labels

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