iOS Development Basics-Fragmentation 14

Source: Internet
Author: User
Tags ziparchive

1:zip file compression with decompression, using ziparchive

Create/Add a Zip package ziparchive* zipfile = [[Ziparchive alloc] init];//times zipfilename requires a complete path, such as ***/documents/demo.zip[ ZipFile createzipfile2:@ "Zipfilename"]; There are two alternative ways to create a compressed package, with a password and without a password [[ZipFile createzipfile2:@] zipfilename "password:@" Your Password "];// The next step is to add the files that need to be compressed into the compressed package//Here The first parameter requires a complete path, for example: ***/documents/a.txt  newname is the name of the file in the compressed package, no path required, just a name [ZipFile addfiletozip:@ "FullPath of the file" newname:@ "new name of the file without path"];//if you need to compress multiple files, that is, compress the folder, Repeat Addfiletozip method can be [ZipFile CloseZipFile2]; Unzip the ZIP package: ziparchive* zipfile = [[Ziparchive alloc] init]; [ZipFile unzipopenfile:@ "ZIP file name"]; Similarly, there are two ways to open the zip package, with a password and without a password [zipfile unzipopenfile:@ "ZIP file name" password:@ "Password"];//the location of the compressed package, need a full path [ ZipFile unzipfileto:@ "Output path" overwrite:yes]; [ZipFile Unzipclosefile]; [ZipFile release];//Remember to release

1. Compression: Ziparchive can compress multiple files, only need to addfiletozip the file one by one. ziparchive* zip = [[Ziparchive alloc] init]; Nsarray *paths = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES); NSString *documentpath = ([Paths count] > 0)? [Paths objectatindex:0]: nil; nsstring* l_zipfile = [documentpath stringbyappendingstring:@ "/test.zip"]; nsstring* image1 = [documentpath stringbyappendingstring:@ "/image1.jpg"];        nsstring* image2 = [documentpath stringbyappendingstring:@ "/image2.jpg"]; BOOL ret = [zip Createzipfile2:l_zipfile];ret = [zip addfiletozip:image1 newname:@ "image1.jpg"];ret = [zip addfiletozip:i Mage2 newname:@ "Image2.jpg"];if (![  Zip CloseZipFile2]) {l_zipfile = @ ""; } 2. Decompression: ziparchive* zip = [[Ziparchive alloc] init]; Nsarray *paths = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES); NSString *documentpath = ([Paths count] > 0)?  [Paths objectatindex:0]: nil; The path address should be noted nsstring* l_zipfile = [Documentpath stringbyappendingstring:@ "/test.zip"]; nsstring* Unzipto = [documentpath stringbyappendingstring:@ "/test"]; if ([Zip Unzipopenfile:l_zipfile]) {BOOL ret = [Z   IP unzipfileto:unzipto Overwrite:yes]; if (No==ret) {} [zip Unzipclosefile]; }

2:uitapgesturerecognizer Pass Value

Uiimageview *imageview =[[uiimageview alloc]initwithframe:cgrectmake (N, A, ())];    imageview.image=[uiimageimagenamed:@ "Filter_laozhaopian_a.png"];    Imageview.tag = 10000;  You can pass this to the bottom of the Click event value    imageview.userinteractionenabled = YES;    UITapGestureRecognizer *singletap = [[Uitapgesturerecognizeralloc] Initwithtarget:selfaction: @selector (UesrClicked :)];    [ImageView Addgesturerecognizer:singletap];    [Self.view addsubview:imageview];-(void) uesrclicked: (UITapGestureRecognizer *) recognizer{   

3: Custom Self.navigationItem.titleView View

UIView *titleview=[[uiview alloc] Initwithframe:cgrectmake (0, 0, Screen_width, ktitleviewheight)];    Latest definition left button UIButton *leftitembutton=[uibutton Buttonwithtype:uibuttontypecustom];    Leftitembutton.frame=cgrectmake (0, 0, kleftitembuttonwidth, kleftitembuttonheight);    [Leftitembutton setbackgroundimage:[uiimage imagenamed:@ "Mapmarknormal"] forstate:uicontrolstatenormal];    [Leftitembutton setbackgroundimage:[uiimage imagenamed:@ "mapmarkselected"] forstate:uicontrolstatehighlighted];    [Leftitembutton addtarget:self Action: @selector (Leftbuttonaction) forcontrolevents:uicontroleventtouchupinside];    [Titleview Addsubview:leftitembutton]; [Leftitembutton mas_makeconstraints:^ (Masconstraintmaker *make)        {Make.centerY.equalTo (Titleview);        Make.left.equalTo (Titleview.mas_left). With.offset (5);    Make.size.equalTo (Cgsizemake (Kleftitembuttonwidth, kleftitembuttonheight));        }];    UILabel *titlelabel=[uilabel New]; Titlelabel.textalignment=nstextaligNmentcenter;    Titlelabel.font=[uifont systemfontofsize:14];    [email protected] "Ha Shan Zhonghua Park Plaza";    [Titleview Addsubview:titlelabel]; [Titlelabel mas_makeconstraints:^ (Masconstraintmaker *make)        {Make.centerY.equalTo (Titleview);    Make.left.equalTo (Titleview.mas_left). With.offset ((screen_width-ktitleviewtitlewidte-10)/2);        }];    UIButton *downbutton=[uibutton New];    [DownButton setimage:[uiimage imagenamed:@ "FileDownload"] forstate:uicontrolstatenormal];    [Titleview Addsubview:downbutton]; [DownButton mas_makeconstraints:^ (Masconstraintmaker *make)        {Make.right.equalTo (titleview.mas_right). With.offset (-2);        Make.centerY.equalTo (Titleview);    Make.size.equalTo (Cgsizemake (Ktitleviewbuttonwidth, ktitleviewbuttonheight));        }];    UILabel *prolabel=[uilabel New];    Prolabel.font=[uifont Systemfontofsize:10];    Prolabel.textcolor=[uicolor Colorwithhexstring:kwittourism_apptextcolor];    Prolabel.textalignment=nstextalignmentright;[email protected] "downloading";        [Titleview Addsubview:prolabel]; [Prolabel mas_makeconstraints:^ (Masconstraintmaker *make)        {Make.right.equalTo (downbutton.mas_left). With.offset (-5);        Make.centerY.equalTo (Titleview);    Make.size.equalTo (Cgsizemake (Ktitleviewlabelwidth, ktitleviewlabelheight));        }]; Self.navigationitem.titleview=titleview;

4: Uiscrollview for unlimited scrolling

The scroll of the picture array to add a head and tail, the header of the front to add a tail, the tail is inserted into the first sheet, and in the scrolling event to process, change its position; The main code is as follows (if not self-written can also find the corresponding plug-in, encapsulated):/** * @author Wujunyang,        15-06-05 13:06:12 * * @brief head scrolling view layout */-(void) setupscrollview{int imgcount=self.imgdatalist.count; If there is no value, replace the display if (imgcount==0) {Uiimageview *featureimageview = [[Uiimageview alloc] with a default picture initwithimage:[uii        Mage imagenamed:@ "Thirdempty"];        Featureimageview.frame=self.headerimageview.frame;    [Self.headerimageview Addsubview:featureimageview];        } else{//actual number of pictures _actualimgnum=self.imgdatalist.count;  To achieve infinite scrolling first insert an element in front of this element for the last [self.imgdatalist insertobject:[self.imgdatalist objectatindex: ([self.imgdatalist        COUNT]-1)] atindex:0];         In the latter one, add a previous first one because the above has been inserted a value so the first one becomes the second so here is 1 [self.imgdatalist addobject:[self.imgdatalist objectatindex:1];        The added number is used to process the total width of the defined scrolling view content int imagdatalistcount=self.imgdatalist.count;        _scrollview=[[uiscrollview Alloc]init]; _scrolLview.frame=self.headerimageview.frame; for (int i=0; i<self.imgdatalist.count; i++) {aroundimgbean* aroundimgbean=[self.imgdatalist objectAtIndex:            I];            Get picture NSString *featureimagename = Aroundimgbean.aroundimgurl;            Uiimageview *featureimageview = [[Uiimageview alloc] init]; [Featureimageview sd_setimagewithurl:[nsurl Urlwithstring:featureimagename] Placeholderimage:[uiimage imageNamed:@                        "Thirdempty"];            Set picture size position cgfloat featurewidth = screen_width;            CGFloat featureheight = self.headerImageView.frame.size.height;            CGFloat Featurex = screen_width * i;            CGFloat Featurey = 0;            Featureimageview.frame = CGRectMake (Featurex, Featurey, Featurewidth, featureheight);        [_scrollview Addsubview:featureimageview];        }//Set ScrollView function Property _scrollview.userinteractionenabled = YES;       _scrollview.bounces=no; _scrollview.scrollenabled = YES; Support scrolling _scrollview.contentsize = Cgsizemake (self.headerImageView.frame.size.width * imagdatalistcount, 0); Only need to scroll horizontally _scrollview.pagingenabled = YES; Support paging _scrollview.showshorizontalscrollindicator = NO;                Hide horizontal scroll bar//set proxy _scrollview.delegate = self;    Add [Self.headerimageview Addsubview:_scrollview]; }}//scrolling Event-(void) Scrollviewdidscroll: (Uiscrollview *) Myscrollview {if ([Myscrollview Isequal:_scrollview]) {//rounding        , let the picture scroll over the midline when changing the page number if (self.imgdatalist.count>0) {cgfloat pagewidth = _scrollview.frame.size.width;        int page = Floor ((_SCROLLVIEW.CONTENTOFFSET.X-PAGEWIDTH/2)/pagewidth) + 1;        _currentpageindex=page; If the current page does not exceed the actual value if (_currentpageindex<_actualimgnum) {_imagecount=[nsstring stringwithformat:@ "%d/        %d ", _currentpageindex+1,_actualimgnum]; } else {_imagecount=[nsstring Stringwithformat:@ "%d/%d", 1,_actualimgnum];    } Self.imagelabel.text=_imagecount;        } else {_imagecountview.hidden=yes;    _imagelabel.hidden=yes; }}}/** * @author Wujunyang, 15-06-05 11:06:06 * * @brief scrolling event handling infinite scrolling Modify the current position of scrolling * @param Myscrollview < #myscroll View description#> */-(void) scrollviewdidenddecelerating: (Uiscrollview *) myscrollview{if ([Myscrollview isEqual: _scrollview]) {if (_currentpageindex==0) {[_scrollview setcontentoffset:cgpointmake ([self        . Imgdatalist count]-2) *myscrollview.frame.size.width, 0)]; } if (_currentpageindex== ([self.imgdatalist count]-1)) {[_scrollview Setcontentoffset:cgpoi        Ntmake (myscrollView.frame.size.width, 0)]; }    }}

iOS Development Basics-Fragmentation 14

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.