我们在网上浏览新闻或者用手机移动设备会常常 使用图片浏览器
图片浏览器 就是能够让用户选择 进行上翻下翻浏览图片信息
当图片浏览到最后一张的时候,那么箭头会变成灰色 不能再进行点击
假设图片浏览在第一张。我们也不能再进行点击
那么我们进行一下简单的分析实现
#import "ViewController.h" @interface ViewController () - (IBAction)previous; - (IBAction)next; @property (weak, nonatomic) IBOutlet UIButton *preBtn; @property (weak, nonatomic) IBOutlet UIButton *nextBtn; @property (weak, nonatomic) IBOutlet UILabel *noLabel; @property (weak, nonatomic) IBOutlet UIImageView *iconView; @property (weak, nonatomic) IBOutlet UILabel *descLabel; //记录当前显示的是第几张图片 @property(nonatomic,assign)int index; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.index = -1; [self next]; /* //1、设置索引 self.noLabel.text = @"1/5"; //2.图片 self.iconView.image = [UIImage imageNamed:@"biaoqingdi"]; //3.描写叙述 self.descLabel.text = @"哈哈"; self.preBtn.enabled = NO; */ // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark 切换图片 -(void)changeData { self.preBtn.enabled = (self.index!=0); self.nextBtn.enabled = (self.index!=4); switch (self.index) { case 0: self.noLabel.text = @"1/5"; self.iconView.image = [UIImage imageNamed:@"biaoqingdi"]; self.descLabel.text=@"表情"; break; case 1: self.noLabel.text = @"2/5"; self.iconView.image = [UIImage imageNamed:@"wangba"]; self.descLabel.text = @"八号"; break; case 2: self.noLabel.text = @"3/5"; self.iconView.image = [UIImage imageNamed:@"bingli"]; self.descLabel.text = @"这也忒严重了"; break; case 3: self.noLabel.text = @"4/5"; self.iconView.image = [UIImage imageNamed:@"chiniupa"]; self.descLabel.text = @"这样子。。。"; break; case 4: self.noLabel.text = @"5/5"; self.iconView.image = [UIImage imageNamed:@"danteng"]; self.descLabel.text = @"能不能换个网名"; break; default: break; } } #pragma mark 上一张 - (IBAction)previous { self.index--; [self changeData]; // self.preBtn.enabled = (self.index!=0); // self.nextBtn.enabled = (self.index!=4); /* if (self.index==0) { self.preBtn.enabled = NO; } else self.preBtn.enabled = YES; if (self.index == 4) { self.nextBtn.enabled = NO; } else self.nextBtn.enabled = YES; */ /* switch (self.index) { case 0: self.noLabel.text = @"1/5"; self.iconView.image = [UIImage imageNamed:@"biaoqingdi"]; self.descLabel.text=@"表情"; break; case 1: self.noLabel.text = @"2/5"; self.iconView.image = [UIImage imageNamed:@"wangba"]; self.descLabel.text = @"八号"; break; case 2: self.noLabel.text = @"3/5"; self.iconView.image = [UIImage imageNamed:@"bingli"]; self.descLabel.text = @"严重了"; break; case 3: self.noLabel.text = @"4/5"; self.iconView.image = [UIImage imageNamed:@"chiniupa"]; self.descLabel.text = @"这样子。
。
。
"; break; case 4: self.noLabel.text = @"5/5"; self.iconView.image = [UIImage imageNamed:@"danteng"]; self.descLabel.text = @"能不能换个网名"; break; default: break; } */ //self.index = self.index -1; } #pragma mark 下一张 - (IBAction)next { self.index++; [self changeData]; /* switch (self.index) { case 0: self.noLabel.text = @"1/5"; self.iconView.image = [UIImage imageNamed:@"biaoqingdi"]; self.descLabel.text=@"表情帝"; break; case 1: self.noLabel.text = @"2/5"; self.iconView.image = [UIImage imageNamed:@"wangba"]; self.descLabel.text = @"选八号"; break; case 2: self.noLabel.text = @"3/5"; self.iconView.image = [UIImage imageNamed:@"bingli"]; self.descLabel.text = @"严重了"; break; case 3: self.noLabel.text = @"4/5"; self.iconView.image = [UIImage imageNamed:@"chiniupa"]; self.descLabel.text = @"这样子。。。"; break; case 4: self.noLabel.text = @"5/5"; self.iconView.image = [UIImage imageNamed:@"danteng"]; self.descLabel.text = @"能不能换个网名"; break; default: break; } */ } @end