从 UIPickerView 获取带有图像的 UIView

发布于 2024-11-16 07:22:20 字数 330 浏览 2 评论 0原文

我有一个 UIPicker 视图,包含 4 列,每列中有 6 个图像的相同数组(颜色)。我有一个按钮,按下该按钮后,将在 UIPickerView 上以单独的视图显示 4 个图像。问题是,我似乎找不到从 UIPickerView 获取 UIView 的方法。

这是完成的应用程序的外观图片: 在此处输入图像描述

正如您所看到的,用户将把 4 列设置为某些颜色,并且当他们按下“猜测”按钮时,它应该在下面的空间中显示 4 个猜测(在 ImageView 中或在画布中)。

预先感谢您提供的任何帮助:)

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:
enter image description here

As you 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 :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七度光 2024-11-23 07:22:20

您可以通过调用 viewForRow:forComponent: 方法来获取特定视图的视图。

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

其他组件依此类推。

这里的问题是,您不能将其作为子视图添加到另一个视图,因为任何视图只能有一个超级视图。您应该获取可能用作数据源的颜色。

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

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

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文