• 图片浏览器


    我们在网上浏览新闻或者用手机移动设备会常常 使用图片浏览器 

    图片浏览器 就是能够让用户选择 进行上翻下翻浏览图片信息

    当图片浏览到最后一张的时候,那么箭头会变成灰色 不能再进行点击

    假设图片浏览在第一张。我们也不能再进行点击 

    那么我们进行一下简单的分析实现

    #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



  • 相关阅读:
    B-S 期权定价模型
    可转债溢价率
    队列模拟递归遍历目录(广度遍历)
    栈模拟递归遍历目录(深度遍历)
    什么人适合学习Django?
    Python学习笔记———递归遍历多层目录
    树莓派开机自启动程序的设置,两步即可。
    7行代码对百万张照片统一改名。
    tornado上帝视角第一次建立WEB服务器
    武沛齐模态对话框课堂作业
  • 原文地址:https://www.cnblogs.com/liguangsunls/p/7205854.html
Copyright © 2020-2023  润新知