【发布时间】:2011-01-24 03:57:26
【问题描述】:
在图像视图中,如何在 iPhone 中以编程方式添加下一个和上一个按钮(前后选项)?
【问题讨论】:
在图像视图中,如何在 iPhone 中以编程方式添加下一个和上一个按钮(前后选项)?
【问题讨论】:
在图像视图中添加按钮?
如果是,代码如下
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]];
}
【讨论】:
将所有图像放入一个数组(let imageArray)并为当前图像获取整数类型的全局变量(let curIndex) 分别递增和递减全局变量nextbuttonAction和prevbuttonAction
并从索引 curIndex ([imageArray objectAtIndex:curIndex]) 中的 imageArray 更改 imageview 控件的图像
【讨论】: