gpt4 book ai didi

objective-c - 在 objective-c 中将一个图像放在另一个图像之上用于按钮

转载 作者:行者123 更新时间:2023-11-29 13:25:14 24 4
gpt4 key购买 nike

我想在另一张图片上显示一张图片。基本上我试图显示该框已选中。问题是,当单击未选中的图像时,会出现复选按钮,但复选框会消失。我希望复选符号出现在复选框的顶部。

代码如下所示:

if (ShopCartUnedited) {
[button setBackgroundImage:[UIImage imageNamed:@"none.png"] forState:UIControlStateNormal];
[arrOfObjects addObject:@"NO"];
}
else {
if (counter+1 <= nQty) {
[button setBackgroundImage:[UIImage imageNamed:@"check2.png"] forState:UIControlStateNormal];
[arrOfObjects addObject:@"YES"];
}
else {
[button setBackgroundImage:[UIImage imageNamed:@"none.png"] forState:UIControlStateNormal];
[arrOfObjects addObject:@"NO"];
}
}

如果单击时如何更改 check2.png 位于 none.png 之上...

最佳答案

您可以有两张不同的图片,一张有复选标记,另一张没有复选标记,然后在它们之间切换。如果那不可能,您需要在 check2.png

的按钮顶部添加一个单独的 ImageView
//create an imageview and add on button, adjust the frame as required.
[button addSubview:imageview];
imageview.userInteractionEnabled = NO;//if button is not accepting the touches
[button setBackgroundImage:[UIImage imageNamed:@"none.png"] forState:UIControlStateNormal];

if (ShopCartUnedited) {
[imageview setImage:nil];
[arrOfObjects addObject:@"NO"];
}
else {
if (counter+1 <= nQty) {
[imageview setImage:[UIImage imageNamed:@"check2.png"]];
[arrOfObjects addObject:@"YES"];
}
else {
[imageview setImage:nil];
[arrOfObjects addObject:@"NO"];
}
}

或者代替这个 if-else block ,只使用

        if ((ShopCartUnedited) || (counter+1 > nQty)) {
[imageview setImage:nil];
[arrOfObjects addObject:@"NO"];
} else {
[imageview setImage:[UIImage imageNamed:@"check2.png"]];
[arrOfObjects addObject:@"YES"];
}

关于objective-c - 在 objective-c 中将一个图像放在另一个图像之上用于按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13301872/

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