A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 余丽丽 高级黑马   /  2015-8-5 23:22  /  755 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文


代码如下:
#import "ViewController.h"
#define HMICON @"icon"
#define HMINFO @"info"

typedef enum{kBack=1,kNext}kTag;
@interface ViewController ()
@property(nonatomic,assign)int index;
@property (weak, nonatomic) IBOutlet UILabel *pageLabel;
@property (weak, nonatomic) IBOutlet UILabel *infoLabel;
@property (weak, nonatomic) IBOutlet UIButton *backButton;
@property (weak, nonatomic) IBOutlet UIButton *nextButton;
@property (weak, nonatomic) IBOutlet UIImageView *iconImag;
@property(nonatomic,strong)NSArray* imageArray;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.index = 0;
    //刷新图片
    [self refreshImage];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//懒加载
-(NSArray *)imageArray
{
    if (_imageArray==nil) {
        NSDictionary*image01 = @{HMICON:@"biaoqingdi",HMINFO:@"在他面前,其他神马表情都弱爆了!"};
        NSDictionary*image02 = @{HMICON:@"wangba",HMINFO:@"哥们为什么选八号呢"};
        NSDictionary*image03 = @{HMICON:@"bingli",HMINFO:@"这也忒狠了"};
        NSDictionary*image04 = @{HMICON:@"chiniupa",HMINFO:@"这小姑娘吃个牛排比杀牛还费劲啊"};
        NSDictionary*image05 = @{HMICON:@"danteng",HMINFO:@"亲,你能改下你的网名么?哈哈"};
        NSDictionary*image06 = @{HMICON:@"1",HMINFO:@"新增1"};
        NSDictionary*image07 = @{HMICON:@"3",HMINFO:@"3"};
        _imageArray = @[image01,image02,image03,image04,image05,image06,image07];

    }

    return _imageArray;
}

-(void)refreshImage
{
    self.pageLabel.text = [NSString stringWithFormat:@"%d/%lu",self.index+1,self.imageArray.count];
    self.infoLabel.text = self.imageArray[self.index][HMINFO];
    self.iconImag.image = [UIImage imageNamed:self.imageArray[self.index][HMICON]];

    self.backButton.enabled =(self.index!=0);
    self.nextButton.enabled =(self.index!=self.imageArray.count-1);

}
- (IBAction)clickButtons:(UIButton *)sender {
    switch (sender.tag) {
        case kBack:
            self.index--;
            break;
        case kNext:
            self.index++;
            break;
    }

    [self refreshImage];

}


@end



2 个回复

倒序浏览
大神啊!!!
回复 使用道具 举报

哈哈!谢谢美女夸奖!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马