Adding image together with text in a picker view

时光总嘲笑我的痴心妄想 提交于 2020-01-06 19:50:19

问题


Can we add image together with text in a picker view? Anyone please help!


回答1:


In picker view's delegate there is

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

method, where you can create your custom view (may be UIView with UILabel and UIImageView in your case) and return it - so UIPickerView will use it for row representation. See reference for more information.

If you return UIView* in this method you may also need to set its userInteractionEnabled property to NO, otherwise picker will not select rows if you tap them.




回答2:


The short answer is Yes. You just do the same as you do with UITableView. Creating a custom view to return to the delegate method is all you need to do.



来源:https://stackoverflow.com/questions/2532490/adding-image-together-with-text-in-a-picker-view

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