iOS开发-图片浏览器(优化)

//

//  ViewController.m

//  19-图片浏览器

//

//  Created by hongqiangli on 2017/7/31.

//  Copyright © 2017年 李洪强. All rights reserved.

//

#import "ViewController.h"

@interface ViewController ()

/**

记录当前的索引号

*/

@property(nonatomic,assign)int index;

/**

上一张

*/

- (IBAction)previous;

/**

下一张

*/

- (IBAction)next;

/**

描述

*/

@property (weak, nonatomic) IBOutlet UILabel *descLabel;

/**

上一个按钮

*/

@property (weak, nonatomic) IBOutlet UIButton *previousBtn;

/**

下一个按钮

*/

@property (weak, nonatomic) IBOutlet UIButton *nextBtn;

/**

索引label

*/

@property (weak, nonatomic) IBOutlet UILabel *noLabel;

@property (weak, nonatomic) IBOutlet UIImageView *mainImageView;

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

[self changData];

}

/**

点击上一张

*/

- (IBAction)previous {

_index--;

[self changData];

}

/**

下一张

*/

- (IBAction)next {

_index++;

[self changData];

}

- (void)changData{

switch (_index) {

case 0:

_noLabel.text = @"1/5";

_mainImageView.image = [UIImage imageNamed:@"biaoqingdi"];

_descLabel.text = @"在他前面,其他什么表情都弱爆了!";

break;

case 1:

_noLabel.text = @"2/5";

_mainImageView.image = [UIImage imageNamed:@"wangba"];

_descLabel.text = @"哥们为什么选择八号呢";

break;

case 2:

_noLabel.text = @"3/5";

_mainImageView.image = [UIImage imageNamed:@"bingli"];

_descLabel.text = @"这也忒狠了";

break;

case 3:

_noLabel.text = @"4/5";

_mainImageView.image = [UIImage imageNamed:@"chiniupa"];

_descLabel.text = @"这个小姑娘吃个牛排比杀牛还费劲呢";

break;

case 4:

_noLabel.text = @"5/5";

_mainImageView.image = [UIImage imageNamed:@"danteng"];

_descLabel.text = @"亲,你能改下你的网名么?哈哈";

break;

default:

break;

}

//判断按钮能不能点击

_previousBtn.enabled = (_index != 0);

_nextBtn.enabled = (_index != 4);

}

@end

上一篇:Java8之旅(六) -- 使用lambda实现尾递归


下一篇:Linux中断 - 驱动申请中断API