在图片视图中,如何在iPhone中以编程方式添加下一个和上一个按钮(前后选项)?
答案 0 :(得分:2)
在图片视图中添加按钮?
如果是,代码如下
UIButton *nextBut=[UIButton buttonWithType:UIButtonTypeRoundedRect];
nextBut.frame= CGRectMake(x, y, 120, 100);
[nextBut setTitle:@"Next" forState:UIControlStateNormal];
[nextBut addTarget:self action:@selector(nextbuttonAction) forControlEvents:UIControlEventTouchUpInside];
[self.imageView addSubview:nextBut];
[nextBut release];
UIButton *prevBut=[UIButton buttonWithType:UIButtonTypeRoundedRect];
prevBut.frame= CGRectMake(x, y, 120, 100);
[prevBut setTitle:@"Previous" forState:UIControlStateNormal];
[prevBut addTarget:self action:@selector(prevbuttonAction) forControlEvents:UIControlEventTouchUpInside];
[self.imageView addSubview:prevBut];
[prevBut release];
x,y是视图中按钮的位置。
然后编写按钮操作的代码,
-(IBAction)nextbuttonAction
{
//Next Button Action
}
-(IBAction)prevbuttonAction
{
//Previous Button Action
}
修改强>
设置pickerView委托。在以下方法代码中,如下所示,
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
imageView.image=[UIImage imageNamed:[imageArray objectAtIndex:row]];
}
答案 1 :(得分:0)
将所有图像放在一个数组中(让imageArray)并为当前图像获取整数类型的全局变量(让curIndex) 分别增加和减少全局变量nextbuttonAction和prevbuttonAction
从imageArray中更改imageview控件的图像来自index curIndex([imageArray objectAtIndex:curIndex])