UIAlertController和UIImagePickerController的使用

UIAlertController 解释:下拉菜单
UIImagePickerController 解释:照片选取器


1.UIAlertController

//1.声明
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
//2.增加一行按钮
[alert addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
    {
//点击按钮相应
        NSLog(@"拍照"
    );
//3.显示
[self presentViewController:alert  animated:YES completion:nil];

2.UIImagePickerController

//1.包含代理
< UIImagePickerControllerDelegate>
//2.声明(可显示)
UIImagePickerController *imagePick = [[UIImagePickerController alloc]init];
 [self presentViewController:imagePick animated:YES completion:nil];  
//3.设置
 imagePick.allowsEditing = YES;    //图片可点击
 imagePick.delegate = self;            // 委托代理
//4.代理函数(选中相片后执行的操作)
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
//将UIImageView上的视图设为自己选择的图片
    [self.mainImageView setImage:image];
//隐藏此视图
    [self dismissViewControllerAnimated:YES completion:nil];
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值