UI基础-04图片浏览器

<pre name="code" class="objc">//
//  ViewController.m
//  UI基础-04图片浏览器
//
//  Created by  NorthCity on 15/9/7.
//  Copyright (c) 2015年 Tcg. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *indexLabel;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

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

@property (weak, nonatomic) IBOutlet UIButton *rightButton;
@property (weak, nonatomic) IBOutlet UILabel *infoLabel;
//数组保存图片信息和图片名字的字典
@property(strong,nonatomic) NSArray *imageData;

//index用来指示第几张图片
@property(nonatomic,assign) int index;

@end

@implementation ViewController


- (void)viewDidLoad {
    self.index = 0;
    [self reloadView];
    
}

//这里重写数组的get方法,好处随用随取
-(NSArray*)imageData{
    if (_imageData == nil) {
        //        注意这里用可变字典啊
        NSMutableDictionary *imge0 =[NSMutableDictionary dictionary];
        imge0[@"icon"] = @"biaoqingdi";
        imge0[@"info"] = @"在他面前,其他神马表情都弱爆了!";
        
        NSMutableDictionary *imge1 =[NSMutableDictionary dictionary];
        imge1[@"icon"] = @"wangba";
        imge1[@"info"] = @"哥们为什么选八号呢";
        
        
        NSMutableDictionary *imge2 =[NSMutableDictionary dictionary];
        imge2[@"icon"] = @"bingli";
        imge2[@"info"] = @"这也忒狠了";
        
        
        NSMutableDictionary *imge3 =[NSMutableDictionary dictionary];
        imge3[@"icon"] = @"chiniupa";
        imge3[@"info"] = @"这小姑娘吃个牛排比杀牛还费劲啊";
        
        
        NSMutableDictionary *imge4 =[NSMutableDictionary dictionary];
        imge4[@"icon"] = @"danteng";
        imge4[@"info"] = @"亲,你能改下你的网名么?哈哈";
        
        
        _imageData = @[imge0,imge1,imge2,imge3,imge4];
        
    }
    return  _imageData;
}
-(void)reloadView{
    self.indexLabel.text =[ NSString stringWithFormat:@"%d/%lu",self.index+1,(unsigned long)self.imageData.count];
    
    self.imageView.image = [UIImage imageNamed:self.imageData[self.index][@"icon"]];
    self.infoLabel.text = self.imageData[self.index][@"info"];
    [self changeButtonState];

}

- (IBAction)clickLeftButton:(UIButton *)sender {
    self.index--;
    [self reloadView];
}

- (IBAction)clickRightButton:(UIButton *)sender {
    self.index++;
    [self reloadView];
    
    
}
-(void)changeButtonState{
    self.leftButton.enabled = self.index >0;
    self.rightButton.enabled = self.index <4;
}

@end

2



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值