问题
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