• 最基本的添加头像


    @interface PTABabyEditBaseVC ()<UIImagePickerControllerDelegate,UIActionSheetDelegate>
    
    @property (nonatomic) UIImagePickerController *imagePickerController;
    
    @end
    
    @implementation PTABabyEditBaseVC
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
       .......
        
        _headBtn = [[UIButton alloc]initWithFrame:CGRectMake((WIDTH(self.view)-85)/2.0, (HEIGHT(headView)-85)/2.0, 85, 85)];
        [_headBtn.layer setMasksToBounds:YES];
        [_headBtn.layer setCornerRadius:WIDTH(_headBtn)/2.0];
        [_headBtn setBackgroundColor:[UIColor grayColor]];
        [_headBtn addTarget:self action:@selector(toShowCamera) forControlEvents:UIControlEventTouchUpInside];
        [_headBtn setImage:[UIImage imageNamed:@"loginIcon.png"] forState:UIControlStateNormal];
        [headView addSubview:_headBtn];
        
         ........
    }
    
    /**
     *  底部弹框
     */
    - (void)toShowCamera{
        
        UIActionSheet * actionsheet = [[UIActionSheet alloc] initWithTitle:nil
                                                                  delegate:self
                                                         cancelButtonTitle:@"取消"
                                                    destructiveButtonTitle:nil
                                                         otherButtonTitles: @"从相册选取",@"拍照", nil];
        [actionsheet showInView:self.view];
    }
    
    #pragma mark --
    #pragma mark -- UIActionSheetDelegate
    - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
        
        if(buttonIndex==0){
            [self showImagePickerForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
        }else if(buttonIndex==1){
            UIImagePickerController *   imagePicker = [[UIImagePickerController alloc] init];
            imagePicker.delegate = self;
            imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
            imagePicker.allowsEditing = NO;
            [self presentViewController:imagePicker animated:YES completion:nil];
            
        }
        
    }
    
    - (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType
    {
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
        imagePickerController.sourceType = sourceType;
        imagePickerController.delegate = self;
        
        self.imagePickerController = imagePickerController;
        [self presentViewController:self.imagePickerController animated:YES completion:nil];
    }
    
    
    
    #pragma mark --
    #pragma mark -- UIImagePickerControllerDelegate
    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
        
        if ([[info objectForKey:UIImagePickerControllerMediaType] isEqualToString:(NSString*)kUTTypeImage]) {
            UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];
            
            [_headBtn setImage:image forState:UIControlStateNormal];
        }
        [picker dismissViewControllerAnimated:YES completion:nil];
    }
  • 相关阅读:
    hdu 2275数据结构水题
    咨询工具、模型、方法论学习笔记 序
    DevExpress DXperience XtraTreeview 如何获取当前光标所在位置的 Node
    Delphi 各个编译版本的开关值
    把对象序列化到文件中和从文件中反序列化的管理类
    Advantech 硬件控制卡的 c# 接口函数
    Delphi 中的 TTimer 和 .NET Framework 中的 Timer 的计时周期研究
    C#设计模式编程之抽象工厂模式新解
    敏捷开发
    关于HTML静态页面(含自动分页)生成的可行性方案
  • 原文地址:https://www.cnblogs.com/allanliu/p/4482202.html
Copyright © 2020-2023  润新知