//如果点击头像,弹出上传框
UIActionSheet *sheet = [[UIActionSheetalloc]init];
sheet.delegate =self;
// sheet.title = @"设置头像";
[sheetaddButtonWithTitle:@"拍照"];
[sheetaddButtonWithTitle:@"从相册选择"];
[sheetaddButtonWithTitle:@"取消"];
sheet.cancelButtonIndex =2;
[sheetshowInView:self.view];
实现UIActionSheetDelegate代理方法
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIImagePickerController *imagePicker = [[UIImagePickerControlleralloc]init];
imagePicker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate =self;
imagePicker.allowsEditing =YES;
if (buttonIndex ==0) {
// 调用系统摄像头,拍照
if ([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { //UIImagePickerControllerSourceTypeCamera相机模式
picker.sourceType =UIImagePickerControllerSourceTypeCamera;
[selfpresentViewController:pickeranimated:NOcompletion:nil];
}else {
UIAlertView* alertView = [[UIAlertViewalloc]initWithTitle:@""
message:@"当前设备不支持摄像头"
delegate:self
cancelButtonTitle:@"知道了"
otherButtonTitles:nil];
[alertViewshow];
}
}elseif (buttonIndex ==1) {
// 调用系统相册,获取相片
if ([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
//UIImagePickerControllerS
picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
[selfpresentViewController:pickeranimated:NOcompletion:nil];
}
}
}
实现UIImagePickerDelegate代理方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// 获取选择和裁剪图片
_photoImage = (UIImage *)(info[UIImagePickerControllerEditedImage]);
_photoImage = [_photoImagefixOrientation];
_photoImage = [_photoImagescaleTo:CGSizeMake(120.0,120.0)];