UIImageView

图片浏览器的 代码~~ 笔记都在里边了
copy : NSString
strong:一般对象 
weak:UI控件
assign:基本数据类型(int long double)


#import "ViewController.h"
#define IconKey @"icon"  // 字典  放图片名的
#define DescKey @"desc"  // 字典  放描述文字的

@interface ViewController ()
- (IBAction)previous;
- (IBAction)next;

@property (weak, nonatomic) IBOutlet UILabel *noLabel;// 编号 文本
@property (weak, nonatomic) IBOutlet UIImageView *headView;// 图片框
@property (weak, nonatomic) IBOutlet UILabel *descLabel;// 描述文本

@property (weak, nonatomic) IBOutlet UIButton *previousBtn;// 左按钮 想让其失效的一个属性
@property (weak, nonatomic) IBOutlet UIButton *nextBtn; // 右按钮
// 记录当前是第几张图片~
@property (nonatomic, assign) int index;
// 图片数据集合
@property (nonatomic, strong) NSArray *imageData;
// strong:一般对象  weak:UI控件
@end

@implementation ViewController
- (void)viewDidLoad
{// 修改 初始化值
   
    [super viewDidLoad];
    // 用 字典 数据初始化
       // 更新数据
    [self changeData]; 第一次加载的时候 要判断一下
}

// 将属性放到 get方法里 懒加载~
- (NSArray *)imageData // 数据的延迟 加载 再用到的时候再加载
{
    if (_imageData == nil) { // 从未初始化
        // 用plist 文件 加载数据
        // file:全路径
        // NSBundle : 一个NSBundle就代表了 一个文件夹
        // mainBundle 可以访问手机里的任何 文件夹
        NSBundle *bundle = [NSBundle mainBundle];
       
        // 获得 文件的 全路径  名字加 扩展名
        NSString *path = [bundle pathForResource:@"imageData" ofType:@"plist"];
        _imageData = [NSArray arrayWithContentsOfFile:path];
      
//        // 数据初始化
//        NSMutableDictionary *image1 = [NSMutableDictionary dictionary];
//        image1[IconKey] = @"1";
//        image1[DescKey] = @"lalalala";
//        NSMutableDictionary *image2 = [NSMutableDictionary dictionary];
//        image2[IconKey] = @"2";
//        image2[DescKey] = @"caocao";
//        NSMutableDictionary *image3 = [NSMutableDictionary dictionary];
//        image3[IconKey] = @"3";
//        image3[DescKey] = @"wawa";
//       
//        // 把 字典 放到数组里~
//        _imageData = @[image1, image2, image3];
    }
    return _imageData;
}

- (void)changeData
{
    // 序号文本框的 输入
    self.noLabel.text = [NSString stringWithFormat:@"%d/%ld",self.index + 1,self.imageData.count];// 记录值/图片总数
   
    // 把 图片按编号 赋给 字典imageDict
    NSDictionary *imageDict = self.imageData[self.index];
   
    // 添加图片                                图片字典 名字
    self.headView.image = [UIImage imageNamed:imageDict[IconKey]];
    // 添加 描述
    self.descLabel.text = imageDict[DescKey];
   
    // 第一张图片时  左按钮 失效
    self.previousBtn.enabled = (self.index != 0);
    //self.previousBtn.enabled = NO; // 不可用状态~
    // 最后一张图片时  右按钮 失效
    self.nextBtn.enabled = (self.index != self.imageData.count-1);  
}
#pragma mark 上一张
- (IBAction)previous {
    // 减小索引
    self.index --;
    // 改变数据
    [self changeData];
}
#pragma mark 下一张
- (IBAction)next {
    // 增加索引
    self.index ++;
    // 根据索引显示对应内容
    [self changeData];
}
@end

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值