186 using albums in the system

Source: Internet
Author: User

PS: For the camera option, the camera is called and requires a real machine to test.

The effect is as follows:

ViewController.h

1 #import <UIKit/UIKit.h>23@interface Viewcontroller:uiviewcontroller <uiactionsheetdelegate, Uiimagepickercontrollerdelegate, uinavigationcontrollerdelegate>4 @ Property (Strong, Nonatomic) Uiimageview *Imgvcustom; 5 6 @end

Viewcontroller.m

1 #import "ViewController.h"2 3 @interfaceViewcontroller ()4- (void) Layoutui;5- (void) Showactionsheet: (Uibarbuttonitem *) sender;6- (voidImage: (UIImage *) image didfinishsavingwitherror: (nserror *) Error ContextInfo: (void*) ContextInfo;7 @end8 9 @implementationViewcontrollerTen  One- (void) Viewdidload { A [Super Viewdidload]; -      - [self layoutui]; the } -  -- (void) didreceivememorywarning { - [Super didreceivememorywarning]; +     //Dispose of any resources the can be recreated. - } +  A- (void) Viewwillappear: (BOOL) Animated { at [Super viewwillappear:animated]; - [Self.navigationcontroller setnavigationbarhidden:no animated:animated]; - [Self.navigationcontroller settoolbarhidden:no animated:animated]; - } -  -- (void) Layoutui { inSelf.navigationItem.title =@"use albums in the system"; -Self.view.backgroundColor =[Uicolor Whitecolor]; toUibarbuttonitem *barbtnchooseimage =[[Uibarbuttonitem alloc] + Initwithbarbuttonsystemitem:uibarbuttonsystemitemcamera - target:self the Action: @selector (Showactionsheet:)]; *Self.toolbaritems =@[barbtnchooseimage]; $     Panax Notoginseng_imgvcustom =[[Uiimageview alloc] initWithFrame:self.view.bounds]; -_imgvcustom.contentmode =Uiviewcontentmodescaleaspectfit; the_imgvcustom.autoresizingmask = Uiviewautoresizingflexiblewidth |Uiviewautoresizingflexibleheight; +_imgvcustom.image = [UIImage imagenamed:@"1"]; A [Self.view Addsubview:_imgvcustom]; the } +  -- (void) Showactionsheet: (Uibarbuttonitem *) Sender { $Uiactionsheet *actionsheet = [[Uiactionsheet alloc] Initwithtitle:@"Select album" $                                                              Delegate: Self -Cancelbuttontitle:@"Cancel" - Destructivebuttontitle:nil theOtherbuttontitles:@"photolibrary",@"Camera",@"Savedphotosalbum", nil]; - [Actionsheet ShowFromToolbar:self.navigationController.toolbar];Wuyi } the  -- (voidImage: (UIImage *) image didfinishsavingwitherror: (nserror *) Error ContextInfo: (void*) ContextInfo { Wu     if(Error) { -NSLog (@"%@", [Error localizeddescription]); About     } $ } -  - #pragmaMark-uiactionsheetdelegate -- (void) Actionsheet: (Uiactionsheet *) Actionsheet Clickedbuttonatindex: (Nsinteger) Buttonindex { A     if(Buttonindex! =actionsheet.cancelbuttonindex) { +Uiimagepickercontrollersourcetype sourcetype =Buttonindex; the         if([Uiimagepickercontroller Issourcetypeavailable:sourcetype]) { -Uiimagepickercontroller *imagepickercontroller =[[Uiimagepickercontroller alloc] init]; $Imagepickercontroller.Delegate=Self ; theImagepickercontroller.sourcetype =sourcetype; theImagepickercontroller.allowsediting =YES; the [Self Presentviewcontroller:imagepickercontroller the Animated:yes - Completion:nil]; in         } the     } the } About  the #pragmaMark-uiimagepickercontrollerdelegate the- (void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary *) Info { theUIImage *imgchoice =[Info objectforkey:uiimagepickercontrollereditedimage]; +     if(!Imgchoice) { -Imgchoice =[Info objectforkey:uiimagepickercontrolleroriginalimage]; the     }Bayi_imgvcustom.image =Imgchoice; the      the     //Save the picture to the album - //uiimagewritetosavedphotosalbum (Imgchoice, - //Self , the //@selector (image:didFinishSavingWithError:contextInfo:), the //NULL); the      the [self imagepickercontrollerdidcancel:picker]; - } the  the- (void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) Picker { the [self dismissviewcontrolleranimated:yes completion:nil];94 } the  the @end

AppDelegate.h

1 #import <UIKit/UIKit.h>23@interface Appdelegate:uiresponder < Uiapplicationdelegate>4 @property (Strong, Nonatomic) UIWindow *window; 5 @property (Strong, Nonatomic) Uinavigationcontroller *Navigationcontroller; 6 7 @end

Appdelegate.m

1 #import "AppDelegate.h"2 #import "ViewController.h"3 4 @interfaceappdelegate ()5 @end6 7 @implementationappdelegate8 9-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {Ten_window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]; OneViewcontroller *viewcontroller =[[Viewcontroller alloc] init]; A_navigationcontroller =[[Uinavigationcontroller alloc] initwithrootviewcontroller:viewcontroller]; -_window.rootviewcontroller =_navigationcontroller; -     //[_window Addsubview:_navigationcontroller.view];//when _window.rootviewcontroller is associated, this sentence is optional the [_window makekeyandvisible]; -     returnYES; - } -  +- (void) Applicationwillresignactive: (UIApplication *) Application { - } +  A- (void) Applicationdidenterbackground: (UIApplication *) Application { at } -  -- (void) Applicationwillenterforeground: (UIApplication *) Application { - } -  -- (void) Applicationdidbecomeactive: (UIApplication *) Application { in } -  to- (void) Applicationwillterminate: (UIApplication *) Application { + } -  the @end

186 using albums in the system

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.