ios – 如何以编程方式更改uiimageview图像

ios – 如何以编程方式更改uiimageview图像,第1张

概述在我的ios应用程序中,我以编程方式创建uiimageviews, for (int i=0; i<20; i++) { productID=[products objectAtIndex:i]; UIButton * button = [UIButton 在我的ios应用程序中,我以编程方式创建uiimagevIEws,

for (int i=0; i<20; i++) {                                   productID=[products objectAtIndex:i];                                   UIbutton * button = [UIbutton buttonWithType:UIbuttonTypeRoundedRect];                                   [button setFrame:CGRectMake(column*197+38,row*350+8,159,45)];                                   //[button setimage:redbuttonImage forState:UIControlStatenormal];                                   [button addTarget:self                                              action:@selector(buttonAction:)                                    forControlEvents:UIControlEventtouchUpInsIDe];                                   button.tag = productID;                                   [scrollVIEw addSubvIEw:button];                                   UIImageVIEw *imageVIEw = [[UIImageVIEw alloc]initWithFrame:CGRectMake(column*197+170,row*350+25,13,13)];                                   imageVIEw.tag=productID;                                   UIImage *image = [UIImage imagenamed:@"redImage.png"];                                   [imageVIEw setimage:image];                                   [scrollVIEw addSubvIEw:imageVIEw];                               }

在我的buttonActon中,我想将uiimagevIEw的图像更改为另一个图像.但我不能这样做.谁能帮我?谢谢.

解决方法 试试这样,45)]; //[button setimage:redbuttonImage forState:UIControlStatenormal]; [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventtouchUpInsIDe]; button.tag = 100+productID; [scrollVIEw addSubvIEw:button]; UIImageVIEw *imageVIEw = [[UIImageVIEw alloc]initWithFrame:CGRectMake(column*197+170,13)]; imageVIEw.tag=productID; UIImage *image = [UIImage imagenamed:@"redImage.png"]; [imageVIEw setimage:image]; [scrollVIEw addSubvIEw:imageVIEw]; }

将此视图保留在按钮 *** 作方法中,并将imagevIEw标记传递给imgvIEw.tag

UIImageVIEw *img=(UIImageVIEw *)[scrollVIEw vIEwWithTag:imgvIEw.tag];    img.image=[UIImage imagenamed:@"name.png"];
总结

以上是内存溢出为你收集整理的ios – 如何以编程方式更改uiimageview图像全部内容,希望文章能够帮你解决ios – 如何以编程方式更改uiimageview图像所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1035208.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-24
下一篇2022-05-24

发表评论

登录后才能评论

评论列表(0条)

    保存