gpt4 book ai didi

ios - 如何在按钮操作上显示图像

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

我有 10 个 UIImages .当我点击 UIButton它显示在 UIScrollView. But I need to implement the 下用户界面按钮 like **Next**, if用户界面按钮 is clicked first time, it displays the first UIImage`,然后单击它会显示下一个图像。如果单击后退按钮,则应显示上一个图像。

enter image description here

int   currentIndex = 0;
int MAX_COUNT;

NSMutableArray *imageName = [[NSMutableArray alloc] initWithObjects:
@"spices.jpg",
@"spice_powder.jpg",
@"turmeric.jpg",
@"whynani_img3.jpg",
@"spice_blends.jpg",
@"products1.png", nil];

currentIndex = currentIndex + 1;
if(currentIndex > MAX_COUNT) {
currentIndex = MAX_COUNT;
}

for (int i = 0; i<[imageName count]; i++ ) {

UIImageView *mmageView =
[[UIImageView alloc] initWithFrame:CGRectMake(200,200,350,350)];
[mmageView setImage:[UIImage imageNamed:[imageName objectAtIndex:i]]];
[self.view addSubview:mmageView];
}

最佳答案

声明全局图片查看 int在接口(interface)文件中

UIImageView *imgView;
int index;

viewDidLoad:
index = 0;

imgView = [[UIImageView alloc] initWithFrame:CGRectMake(200,200,350,350)];
[imgView setImage:[UIImage imageNamed:[imageName objectAtIndex:index]]];
[self.view addSubView:imgView];

Next Button Action
-(void)nextButtonAction
{
++index;

[previousBtn setEnabled:YES];

if (index > [imageName count])
{
index = [imageName count] - 1;
[nextBtn setEnabled:NO];
}

[imgView setImage:[UIImage imageNamed:[imageName objectAtIndex:index]]];

}

Previous Button Action
-(void)previousButtonAction
{
--index;

[nextBtn setEnabled:YES];

if (index < 0)
{
index = 0;
[previousBtn setEnabled:NO];
}

[imgView setImage:[UIImage imageNamed:[imageName objectAtIndex:index]]];

}

关于ios - 如何在按钮操作上显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22218995/

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