首先採用UIImagePickerController的協議,
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
UIImagePickerController *picker = [[UIImagePickerControlleralloc] init];
picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate =self;
picker.allowsEditing =YES;//這兩句保證了圖片可以裁剪為正方形
picker.allowsImageEditing=YES;///這兩句保證了圖片可以裁剪為正方形
[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];
}