文章标题

“`
//背景点击方法
- (void)bgAction{

UIActionSheet *bgActionImage = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"相册",@"拍照", nil];
bgActionImage.tag = 521;
[bgActionImage showInView:self.view];

}
//头像点击方法
- (void)userAction{

UIActionSheet *headActionImage = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"相册",@"拍照", nil];
headActionImage.tag = 520;
[headActionImage showInView:self.view];

}

pragma mark - 更换背景图片和头像

  • (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
    {
    if (actionSheet.tag == 520) {
    NSLog(@”头像”);
    _isPortrait = YES;
    [self getImage:buttonIndex];
    }else if(actionSheet.tag == 521){
    NSLog(@”背景图片”);
    _isPortrait = NO;
    [self getImage:buttonIndex];
    }
    }

  • (void)getImage:(NSInteger)buttonIndex
    {

    //相册获取
    if (buttonIndex == 0) {

    UIImagePickerController * picker = [[UIImagePickerController alloc]init];
    picker.sourceType =     UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;
    picker.allowsEditing = YES;
    [self presentViewController:picker animated:YES completion:nil];
    

    }else if (buttonIndex == 1){
    UIImagePickerControllerSourceType sourceType= UIImagePickerControllerSourceTypeCamera;
    if ([UIImagePickerController isSourceTypeAvailable:sourceType]) {
    UIImagePickerController *picker = [[UIImagePickerController alloc]init];
    picker.sourceType = sourceType;
    picker.delegate = self;
    picker.allowsEditing = YES;
    [self presentViewController:picker animated:YES completion:nil];
    }else{
    NSLog(@”模拟器打不开拍照功能,请在真机中使用”);
    }

    }
    }

-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:nil];
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage * image = [info objectForKey:UIImagePickerControllerEditedImage];
NSLog(@”isPortrait === %d”,_isPortrait);
if (_isPortrait) {

        [self uploadPhoto:reviseHeadImage_API photoImage:image];

    }else{
        [self uploadPhoto:reviseBackImage_API photoImage:image];
    }
}

}

  • (void)uploadPhoto:(NSString )photoUrl photoImage:(UIImage )image
    {
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSUserDefaults *userdefault = [NSUserDefaults standardUserDefaults];
    NSDictionary *dataDic = [userdefault objectForKey:@”rmxjyData”];
    NSLog(@”photo====%@”,photoUrl);
    [manager POST:[NSString stringWithFormat:@”%@%@”,BaseUrl_API,photoUrl] parameters:[@{
    @”key”:dataDic[@”key”],
    @”userId”:dataDic[@”userId”]
    }mutableCopy] constructingBodyWithBlock:^(id formData) {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    // 设置时间格式
    formatter.dateFormat = @”yyyyMMddHHmmss”;
    NSString *str = [formatter stringFromDate:[NSDate date]];
    NSString *fileName = [NSString stringWithFormat:@”%@.png”, str];
    NSData *headData = UIImageJPEGRepresentation(image, .5);
    [formData appendPartWithFileData:headData name:@”photo” fileName:fileName mimeType:@”image/png”];
    NSLog(@”%@”,formData);
    } success:^(NSURLSessionDataTask *task, id responseObject) {
    NSLog(@”%@”,responseObject);
    if ([responseObject[@”code”] intValue] == 0) {

        [self.personModel getData:^(NSMutableArray *array) {
    
            if (_isPortrait) {
    
                [_userButton setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ImgPath_API,self.personModel.userImage]]]] forState:UIControlStateNormal];
            }else{
    
                [_bgButton setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ImgPath_API,self.personModel.userBackimage]]]] forState:UIControlStateNormal];
            }
            NSLog(@"userImage ====%@",self.personModel.userImage);
        }];
    }
    [hud hide:YES];
    

    } failure:^(NSURLSessionDataTask *task, NSError *error) {
    NSLog(@”%@”,error);
    [hud hide:YES];
    }

}

要想使相册里面的英文变为中文在info.plist文件里面设置如下两个参数
info.plist里面添加
Localizedresources can be mixed YES
Localization native development region China
添加完就OK了
这里写图片描述这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值