zoukankan      html  css  js  c++  java
  • 最基本的添加头像

    @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];
    }
  • 相关阅读:
    说说VNode节点(Vue.js实现)
    从Vue.js源码角度再看数据绑定
    《Cloud Native Infrastructure》CHAPTER 7(3)
    《Cloud Native Infrastructure》CHAPTER 7(2)
    《Cloud Native Infrastructure》CHAPTER 7 (1)
    《Cloud Native Infrastructure》CHAPTER 4(2)
    《Cloud Native Infrastructure》CHAPTER 4(1)
    《Cloud Native Infrastructure》CHAPTER 2(1)
    《Cloud Native Infrastructure》CHAPTER 1(2)
    《Cloud Native Infrastructure》CHAPTER 1(1)
  • 原文地址:https://www.cnblogs.com/allanliu/p/4482202.html
Copyright © 2011-2022 走看看