First, using the Uiimagepickercontroller protocol,
-(void) Actionsheet: (Uiactionsheet *) Actionsheet Clickedbuttonatindex: (Nsinteger) Buttonindex
{
if (Buttonindex = = 0) {
Uiimagepickercontroller *picker = [[Uiimagepickercontrolleralloc] init];
Picker.sourcetype =uiimagepickercontrollersourcetypephotolibrary;
Picker.delegate =self;
Picker.allowsediting =yes;//These two words to ensure that the picture can be cropped to square
picker.allowsimageediting=yes;///these two words to ensure that the picture can be cropped to square
[Selfpresentmodalviewcontroller:picker Animated:yes];
}elseif (Buttonindex = = 1) {
Uiimagepickercontroller *picker = [[Uiimagepickercontrolleralloc] init];
Picker.sourcetype =uiimagepickercontrollersourcetypecamera;
Picker.delegate =self;
Picker.allowsediting =yes;
Picker.allowsimageediting=yes;
[Selfpresentmodalviewcontroller:picker Animated:yes];
}
}
-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker didfinishpickingimage: (UIImage *) Aimage EditingInfo :(nsdictionary *) editinginfo
{
[Headpicsetimage:aimage Forstate:uicontrolstatenormal];
[Picker Dismissmodalviewcontrolleranimated:yes];
}