(pure code) picture browser:

Source: Internet
Author: User

#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:

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.