How to save pictures in a local album in iOS development

Source: Internet
Author: User

-(void) viewdidload {[Super viewdidload];   Self.view.backgroundColor = [Uicolor Whitecolor];    /* There are two ways to save a picture: 1>. button mode;  2> Long press the picture;  *//Display picture _imagev = [[Uiimageview alloc]initwithframe:cgrectmake (100, 100, 200, 200)]; [Note?]: "9.jpg" Here is the name of the picture name, the user changed to the corresponding picture name _imagev.image = [UIImage imagenamed:@ "9.jpg"];//Use gestures must turn on interactivity_imagev.userinteractionenabled = YES;  [Self.view addsubview:_imagev];   //Way One: Add a long press gesture to the picture   Uilongpressgesturerecognizer * longpress = [Uilo Ngpressgesturerecognizer alloc]initwithtarget:self Action: @selector (Longpressclick:)];   //Set long time between  , default 0.5 seconds longpress.minimumpressduration = 1.0; [Self.imagev addgesturerecognizer:longpress];      //Mode two: Create button UIButton * btn = [UIButt  On buttonwithtype:uibuttontypecustom];    Btn.backgroundcolor = [Uicolor Yellowcolor];  [Btn settitle:@ "Save album" Forstate:uicontrolstatenormal];  [Btn settitlecolor:[uicolor Orangecolor] forstate:uicontrolstatenormal];  Btn.frame =cgrectmake (30, 70, 100, 30);  [Self.view ADDSUBVIEW:BTN]; [Btn addtarget:self Action: @selector (Btnclick:) forcontrolevents:uicontroleventtouchupinside];}  //Long press gesture to achieve picture preservation-(void) Longpressclick: (Uigesturerecognizer *) longpress{   //must add a judgment statement to prevent multiple saves      if (longpress.state = = Uigesturerecognizerstatebegan) {       Uiimagewritetosavedphotosalbum (self.imageV.image, Self, @selector (imagesavedtophotosalbum: Didfinishsavingwitherror:contextinfo:), nil);   }}  //button click event Implementation-(void) Btnclick: ( uibutton *) btn{uiimagewritetosavedphotosalbum (Self.imageV.image, Self, @selector (imagesavedtophotosalbum: Didfinishsavingwitherror:contextinfo:), nil);}  //How to save a picture-(void) Imagesavedtophotosalbum: (UIImage *) image didfinishsavingwitherror: (Nserror *) error  ContextInfo: (void *) contextinfo{if (!error) {        NSLog (@ "Success picture saved to album"); }else{        NSLog (@ "%@", Error.localizeddescription);   }}

How to save a picture in a local album in iOS development

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.