gpt4 book ai didi

ios - 使 UIImagePickerController 将所选图像设置为多个 UIImageViews

转载 作者:行者123 更新时间:2023-12-01 19:54:14 25 4
gpt4 key购买 nike

我有 3 个按钮和 3 个 UIImageViews,所有按钮都打开一个 UIImagePickerController。我希望按钮 1 打开 UIImagePickerController,然后将所选图像设置为 UIImageView 1,按钮 2 打开 UIImagePickerController,并将所选图像设置为 UIImageView 2,等等。如何才能做到这一点?谢谢!

最佳答案

您可以为按钮设置标签 (1,2,3) 以确定用户按下了哪个按钮。将此值存储到某个变量中,稍后使用它来确定您需要将从 UIImagePickerController 接收的 UIImage 设置到哪个 UIImageView 中。

更新。
标签可以在 Interface Bulder 或代码中设置:

button1.tag = 1;

要将当前标签使用变量存储在 Controller 中:
@interface NameOfYourController : UIViewController
{
NSInteger currentTag;
}

要获取按钮标记,请在按钮修饰内部事件中使用此:
-(void)buttonTap:(UIButton *)sender
{
currentTag = sender.tag;
}

当 UIImagePickerController 调用媒体拾取完成时,使用存储的标签:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *img = info[UIImagePickerControllerOriginalImage];
if (currentTag==1)
imageView1.image = image;
else if (currentTag==2)
imageView2.image = image;
else if (currentTag==3)
imageView3.image = image;
}

关于ios - 使 UIImagePickerController 将所选图像设置为多个 UIImageViews,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43646083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com