iOS-圖片瀏覽器(字典和plist檔案的使用)

來源:互聯網
上載者:User

標籤: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檔案的使用)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.