ios – 如何以编程方式更改uiimageview图像
发布时间:2020-12-14 18:56:56 所属栏目:百科 来源:网络整理
导读:在我的ios应用程序中,我以编程方式创建uiimageviews, for (int i=0; i20; i++) { productID=[products objectAtIndex:i]; UIButton * button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button setFrame:CGRectMake(column*197+38,row*350+8,15
在我的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"]; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |