ios-Picture Browser (dictionary and plist file usage)

Source: Internet
Author: User

//

VIEWCONTROLLER.M

19- Picture Browser

//

Created by Hongqiangli on 2017/7/31.

Copyright Li Hongqiang year . All rights reserved.

//

#define ICON @"icon"

#define DESC @"desc"

#import "ViewController.h"

@interface viewcontroller ()

/**

record the current index number

*/

@property(nonatomic,assign)int index;

/**

the previous one

*/

-(ibaction) previous;

/**

Next One

*/

-(ibaction) next;

/**

Description

*/

@property (weak, nonatomic) iboutlet UILabel *desclabel;

/**

Previous Button

*/

@property (weak, nonatomic) iboutlet UIButton *previousbtn;

/**

Next button

*/

@property (weak, nonatomic) iboutlet UIButton *nextbtn;

/**

Index label

*/

@property (weak, nonatomic) iboutlet UILabel *nolabel;

@property (weak, nonatomic) iboutlet uiimageview *mainimageview;

/**

General OC objects are modified with strong

*/

@property(nonatomic,strong)Nsarray *images;

@end

@implementation Viewcontroller

-(nsarray *) images{

if(_images = = Nil) {

// Dictionary mode initialization

nsmutabledictionary *dic1 = [nsmutabledictionary dictionary];

Dic1[icon] = @ "Biaoqingdi";

Dic1[desc] = @ " in front of him, other god horse expression is weak!" ";

nsmutabledictionary *dict2 = [nsmutabledictionary dictionary];

dict2[icon]= @ "Wangba";

Dict2[desc] = @ " brother why Choose Eighth ";

nsmutabledictionary *dict3 = [nsmutabledictionary dictionary];

dict3[icon]= @ "Bingli";

Dict3[desc] = @ " that's a cruel!" ";

nsmutabledictionary *dict4 = [nsmutabledictionary dictionary];

dict4[icon]= @ "Chiniupa";

Dict4[desc] = @ " This little girl eats a cow and kills the cows. "

nsmutabledictionary *dict5 = [nsmutabledictionary dictionary];

dict5[icon]= @ "Danteng";

Dict5[desc] = @ " Pro, can you change your screen name?" Haha ";

_images = @[dic1,dict2,dict3,dict4,dict5];

// load in a plist way

// get The full path to the plist file

nsstring *path = [[nsbundle mainbundle]pathforresource:@ "Images" OfType:@ "plist"];

_images = [nsarray arraywithcontentsoffile:p ath];

}

return _images;

}

-(void) viewdidload {

[Super viewdidload];

[self changdata];

}

/**

Click on the previous one

*/

-(ibaction) Previous {

_index--;

[self changdata];

}

/**

Next One

*/

-(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;

// judgment button can not click

_previousbtn.enabled = (_index! = 0);

_nextbtn.enabled = (_index! = 4);

}

@end

ios-Picture Browser (dictionary and plist file usage)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.