UI 和图片相关的知识点

UIActionSheet的初始化方法

 UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"图片" delegate:self cancelButtonTitle:@"two" destructiveButtonTitle:@"从相册选取" otherButtonTitles:@"four", nil];
    [action showInView:self.view];

UIImagePickerController(图片选择器) 1.初始化  2.设置代理人  3.允许编辑  allowsEditing 4.模态跳转 presentViewController ------>在action的点击事件里写

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
//    NSLog(@"%ld", buttonIndex);
    
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    // 设置代理人
    picker.delegate = self;
    // 允许编辑
    picker.allowsEditing = YES;
    // 模态进行跳转
    [self presentViewController:picker animated:YES completion:^{
        
        
    }];
    
}

从本地选取图片  1.dismiss回第一页面  2.从字典里提取info里图片的内容------>imagePicker里写 ------>字典中的key有两个,两种不同的状态

// 从本地选取图片
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    //
    [picker dismissViewControllerAnimated:YES completion:^{
        
    }];
//    NSLog(@"%@", info);
    // 从字典里提取info里的图片内容
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    self.imageView.image = image;


}

将图片存为本地  1.首先需要打开交互userInteractionEnabled  2.创建一个长按的手势  3.在长按的手势里,将图片保存在本地相册, 后面三个参数主要作为保存之后的信息回调,把保存的结果返回

 self.imageView.userInteractionEnabled = YES;
    UILongPressGestureRecognizer *longpress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longpressAction:)];
    [self.imageView addGestureRecognizer:longpress];

- (void)longpressAction:(UILongPressGestureRecognizer *)longpress{
    // 把图片保存到本地相册
    // 后面三个参数主要是作为保存之后的信息回调,把保存的结果返回
    UIImageWriteToSavedPhotosAlbum(self.imageView.image, nil, nil, nil);


}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值