標籤:bundle index bin text list 方式 ges weak undle
//
// ViewController.m
// 19-圖片瀏覽器
//
// Created by hongqiangli on 2017/7/31.
// Copyright ? 2017年 李洪強. All rights reserved.
//
#define icon @"icon"
#define desc @"desc"
#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;
/**
一般的OC對象用strong修飾
*/
@property(nonatomic,strong)NSArray *images;
@end
@implementation ViewController
- (NSArray *)images{
if(_images == nil){
//字典的方式初始化
// NSMutableDictionary *dic1 = [NSMutableDictionary dictionary];
// dic1[icon] = @"biaoqingdi";
// dic1[desc] = @"在他面前,其他神馬錶情都弱爆了!";
// NSMutableDictionary *dict2 = [NSMutableDictionary dictionary];
// dict2[icon]= @"wangba" ;
// dict2[desc] = @"哥們為什麼選八號呢";
// NSMutableDictionary *dict3 = [NSMutableDictionary dictionary];
// dict3[icon]= @"bingli" ;
// dict3[desc] = @"這也忒狠了!";
// NSMutableDictionary *dict4 = [NSMutableDictionary dictionary];
// dict4[icon]= @"chiniupa" ;
// dict4[desc] = @"這小姑娘吃個牛排比殺牛還費勁啊";
// NSMutableDictionary *dict5 = [NSMutableDictionary dictionary];
// dict5[icon]= @"danteng" ;
// dict5[desc] = @"親,你能改下你的網名嗎?哈哈";
// _images = @[dic1,dict2,dict3,dict4,dict5];
//用plist的方式載入
//拿到plist檔案的全路徑
NSString *path = [[NSBundle mainBundle]pathForResource:@"images" ofType:@"plist"];
_images = [NSArray arrayWithContentsOfFile:path];
}
return _images;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self changData];
}
/**
點擊上一張
*/
- (IBAction)previous {
_index--;
[self changData];
}
/**
下一張
*/
- (IBAction)next {
_index++;
[self changData];
}
- (void)changData{
_noLabel.text = [NSString stringWithFormat:@"%d/%ld",_index + 1,_images.count];
NSDictionary *dict = _images[_index];
NSString *iconStr = dict[icon];
NSString *descStr = dict[desc];
_mainImageView.image = [UIImage imageNamed:iconStr];
_descLabel.text = descStr;
//判斷按鈕能不能點擊
_previousBtn.enabled = (_index != 0);
_nextBtn.enabled = (_index != 4);
}
@end
iOS-圖片瀏覽器(字典和plist檔案的使用)