开发者

Getting UIView from UIPickerView with images

I have a UIPicker view containing 4 columns with the same array of 6 images in each column (colors). I have a button which, when pressed, will display the 4 images on the UIPickerView in separate views. Problem is, I can't seem to find a way to get the UIView from a UIPickerView.

Here is a picture of what the finished app will look like:

Getting UIView from UIPickerView with images

As you开发者_Python百科 can see, the user will set the 4 columns to some colors and when they press the Guess button, it should display the 4 guesses in the space below (either in ImageViews or in a canvas).

Thanks in advance for any help you can offer :)


You can get the view for a particular view by calling viewForRow:forComponent: method.

UIView * selectedViewInFirstComponent = [pickerView viewForRow:[pickerView selectedRowInComponent:0] forComponent:0];

and so on for the other components.

The problem here is that you can't add it to another view as subview as there can be only one superview for any view. You should rather get the color which you might be using as the data source.

UIColor * colorForFirstComponent = [colors objectAtIndex:[pickerView selectedRowInComponent:0]];

// Now use this color to fill one of the views in the guess block.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜