IOS Imagepicker use method, easy to use! Three easy steps to get it done!

Source: Internet
Author: User

Their own summary of the method to modify the avatar, only for the convenience of their own query use! Forward

Step: 1, abide by the agency agreement

<uiimagepickercontrollerdelegate,uinavigationcontrollerdelegate,uiactionsheetdelegate >

2. Click event {

uiactionsheet *choosephotoactionsheet;

if([uiimagepickercontroller issourcetypeavailable: Uiimagepickercontrollersourcetypecamera]) {

Choosephotoactionsheet = [[uiactionsheet alloc] initwithtitle:nslocalizedstring (@ " pick picture " @ "")

delegate: Self

cancelbuttontitle:nslocalizedstring(@ " cancel ", @ "")

                         and nbsp                     destructivebuttontitle:nil

otherbuttontitles:nslocalizedstring(@ " camera ", @ ""), nslocalizedstring (@ " album ", @ ""), Nil];

} Else {

Choosephotoactionsheet = [[uiactionsheet alloc] initwithtitle:nslocalizedstring( @ " Choose picture ", @ "")

delegate: Self

cancelbuttontitle:nslocalizedstring(@ " cancel ", @ "")

Destructivebuttontitle

:Nil

otherbuttontitles:nslocalizedstring(@ " album ", @ ""), Nil];

}

[Choosephotoactionsheet showinview:self. View];

}

3. Implement Agent Method

#pragma mark-uiactionsheetdelegate

-(void) Actionsheet: (uiactionsheet *) actionsheet clickedbuttonatindex: (nsinteger) Buttonindex

{

nsuinteger sourcetype = 0;

if([uiimagepickercontroller issourcetypeavailable: Uiimagepickercontrollersourcetypecamera]) {

Switch (buttonindex) {

case 0:

SourceType = Uiimagepickercontrollersourcetypecamera;

break;

case 1:

SourceType = uiimagepickercontrollersourcetypephotolibrary;

break;

case 2:

return;

}

} Else {

if (buttonindex = = 1) {

return;

} Else {

SourceType = uiimagepickercontrollersourcetypesavedphotosalbum;

}

}

uiimagepickercontroller *imagepickercontroller = [[uiimagepickercontroller alloc] init];

Imagepickercontroller. delegate = self;

Imagepickercontroller. allowsediting = YES;

Imagepickercontroller. sourcetype = sourcetype;

[self presentviewcontroller: Imagepickercontroller animated:YES Completion: ^{

}];

}

#pragma mark-uiimagepickercontrollerdelegate

-(void) Imagepickercontroller: (uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: ( nsdictionary *) Info

{

[self dismissviewcontrolleranimated:YES completion: ^{

}];

self. tmpheaderimg = [info objectforkey:uiimagepickercontrollereditedimage];

[self. Imageviewuserhead setimage:self. Tmpheaderimg];

[self uploadimage];

}

-(void) Imagepickercontrollerdidcancel: (uiimagepickercontroller *) Picker

{

[self dismissviewcontrolleranimated:YES completion: ^{

}];

}

IOS Imagepicker use method, easy to use! Three easy steps to get it done!

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.