例:
UIImagePickerControllerSourceTypesourceType =UIImagePickerControllerSourceTypePhotoLibrary;
UIImagePickerController*imagepicker = [[UIImagePickerControlleralloc]init];
imagepicker.delegate=self;
//imagepicker.allowsEditing = YES;
imagepicker.sourceType= sourceType;
[selfpresentViewController:imagepickeranimated:YEScompletion:nil];
1、allowsEditing 和 - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info 决定了带白框选取
{
UIImage*originalImage = [infoobjectForKey:UIImagePickerControllerEditedImage];
如果不设置allowsEditing 和 使用 UIImagePickerControllerorignalImage则不带选取白框功能
显示圆形头像
NSArray*paths= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);NSString*documentsDirectory= [paths objectAtIndex:0];NSString*imageFilePath= [documentsDirectory stringByAppendingPathComponent:@"selfPhoto.jpg"];NSLog(@"imageFile->>%@",imageFilePath);UIImage*selfPhoto= [UIImage imageWithContentsOfFile:imageFilePath];//self.img.image = selfPhoto;[self.img.layer setCornerRadius:CGRectGetHeight([self.img bounds]) /2];//修改半径,实现头像的圆形化self.img.layer.masksToBounds = YES;