Paul Morris
Paul Morris

Reputation: 1773

Changing a UIImageView when a certain row is selected on a UIPickerView

Hopefully someone can help with this, I have a UIPickerView which prompts my user to select a Height and a Weight from the Picker. When selected, it then populates a UILabel with the selected option. Next to each label I want to put a UIImageView which initially starts out displaying a Cross to indicate the required action has not been taken. Then when the user select their values it changes that Image to a tick.

But I cant for the life of me figure out how to go about doing it?

Any advice? Would I place this in the didSelectRow method of the UIPickerView?

Upvotes: 0

Views: 691

Answers (1)

David Neiss
David Neiss

Reputation: 8237

UIImageView can be init'ed with two images, normal and highlighted.

(id)initWithImage:(UIImage *)image highlightedImage:(UIImage *)highlightedImage

Select which one you want to be displayed via the highlighted property.

The picker view's delegate function

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component

can be the place where you set your label and update the highlighted property of the UIImageView.

Upvotes: 1

Related Questions