#import "ViewController.h"#defineKImage @ "Image"#defineKdescribe @ "describe"@interfaceViewcontroller () @property (nonatomic, weak) Uiimageview*Proimageview, @property (nonatomic, weak) UILabel*Prolabimagenumber, @property (nonatomic, weak) UILabel*Prolabimagedescribe, @property (nonatomic, weak) UIButton*Probtnleft, @property (nonatomic, weak) UIButton*probtnright, @property (nonatomic, assign)intindex; @property (nonatomic, strong) Nsarray*ImageData;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; /** Number of pages displayed*/UILabel*labimagenumber = [[UILabel alloc] Initwithframe:cgrectmake (175, -, -, -)]; Labimagenumber.text= [NSString stringWithFormat:@"%d/%lu", self.index+1, Self.imageData.count]; Labimagenumber.textcolor=[Uicolor Greencolor]; [Self.view Addsubview:labimagenumber]; Self.prolabimagenumber=Labimagenumber; /** Image View*/Uiimageview*imageview = [[Uiimageview alloc] initwithimage:[uiimage imagenamed:@"Biaoqingdi"]]; Imageview.frame= CGRectMake ( the, -, $, -); [Self.view Addsubview:imageview]; Self.proimageview=ImageView; /** Left page*/UIButton*btnleft =[UIButton Buttonwithtype:uibuttontypecustom]; Btnleft.frame= CGRectMake ( -, About, -, -); [Btnleft setimage:[uiimage imagenamed:@"Left_normal"] Forstate:uicontrolstatenormal]; [Btnleft setimage:[uiimage imagenamed:@"left_highlighted"] forstate:uicontrolstatehighlighted]; [Btnleft setimage:[uiimage imagenamed:@"left_disable"] forstate:uicontrolstatedisabled]; //Set button status is disabled, parameter enabled is nobtnleft.enabled =NO; [Self.view Addsubview:btnleft]; [Btnleft Settag:1]; [Btnleft addtarget:self Action: @selector (Btnclick:) forcontrolevents:uicontroleventtouchupinside]; Self.probtnleft=Btnleft; /** page Right*/UIButton*btnright =[UIButton Buttonwithtype:uibuttontypecustom]; Btnright.frame= CGRectMake ( -, About, -, -); [Btnright setimage:[uiimage imagenamed:@"Right_normal"] Forstate:uicontrolstatenormal]; [Btnright setimage:[uiimage imagenamed:@"right_highlighted"] forstate:uicontrolstatehighlighted]; [Btnright setimage:[uiimage imagenamed:@"right_disable"] forstate:uicontrolstatedisabled]; [Self.view Addsubview:btnright]; [Btnright Settag:2]; [Btnright addtarget:self Action: @selector (Btnclick:) forcontrolevents:uicontroleventtouchupinside]; Self.probtnright=Btnright; /** Picture Description*/UILabel*labimagedescribe = [[UILabel alloc] Initwithframe:cgrectmake ( -, -, $, -)]; Labimagedescribe.textcolor=[Uicolor Redcolor]; Labimagedescribe.text=@"look at this bear boy ... "; [Self.view Addsubview:labimagedescribe]; Self.prolabimagedescribe=Labimagedescribe; }//override ImageData's Get method-(Nsarray *) imagedata{if(_imagedata = = nil) {//never initialized//Initializing Data//File: Full path//NSBundle: A nsbundle represents a folder//use Mainbundle to access any resource in the software resource bundleNSBundle *bundel =[NSBundle Mainbundle]; NSString*path = [Bundel pathforresource:@"Imageanddescribe"OfType:@"plist"]; _imagedata=[Nsarray Arraywithcontentsoffile:path]; } return_imagedata;}- (void) changeimagedata{//Change Button Stateself.proBtnLeft.enabled = (Self.index! =0 ); Self.proBtnRight.enabled= (Self.index! = self.imagedata.count-1); //Change Labimagenumber control textSelf.proLabImageNumber.text = [NSString stringWithFormat:@"%d/%lu", self.index+1, (unsignedLong) Self.imageData.count]; //2. Remove the dictionary data for indexNsdictionary *imagedict =Self.imagedata[self.index]; //set up a pictureSelf.proImageView.image =[UIImage Imagenamed:imagedict[kimage]]; Self.proLabImageDescribe.text=Imagedict[kdescribe]; }//Monitor- (void) Btnclick: (UIButton *) btn{Switch(Btn.tag) { Case 1: Self.index--; [Self changeimagedata]; Break; Case 2: Self.index++; [Self changeimagedata]; Break; }}@end
(pure code) picture browser: