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!