iOS- 选择图片(相机/相册)
来源:互联网 发布:java贪吃蛇大作战源码 编辑:程序博客网 时间:2024/05/24 02:37
#import "ViewController.h"
@interface ViewController () <UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIActionSheetDelegate>
@property (nonatomic,strong)UIButton * imgBtn;
@end
@implementation ViewController
@synthesize imgBtn;
- (void)viewDidLoad
{
[superviewDidLoad];
self.view.backgroundColor = [UIColorwhiteColor];
[self loadSet];
}
- (void) loadSet
{
imgBtn = [UIButtonbuttonWithType:UIButtonTypeCustom];
imgBtn.frame =CGRectMake(100,100, 200, 200);
imgBtn.backgroundColor = [UIColorgrayColor];
[imgBtnsetTitleColor:[UIColorblackColor] forState:UIControlStateNormal];
[imgBtnsetTitle:@"上传头像"forState:UIControlStateNormal];
[imgBtnaddTarget:selfaction:@selector(uploadImage)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:imgBtn];
}
#pragma mark - 上传头像
- (void) uploadImage
{
UIActionSheet * sheet = [[UIActionSheetalloc]initWithTitle:nildelegate:selfcancelButtonTitle:@"取消"destructiveButtonTitle:nilotherButtonTitles:@"相机",@"相册",nil];
[sheet showInView:self.view];
}
#pragma mark - sheet 的 代理方法
- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"%ld",buttonIndex);
if (buttonIndex == 0)
{//相机
UIImagePickerController *aImgPickerCtrl = [[UIImagePickerControlleralloc] init];
aImgPickerCtrl.delegate = self;
[aImgPickerCtrl setAllowsEditing:YES];
if (![UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
[aImgPickerCtrl setSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum];
}
else
{
[aImgPickerCtrl setSourceType:UIImagePickerControllerSourceTypeCamera];
}
[selfpresentViewController:aImgPickerCtrl animated:YEScompletion:Nil];
}
if (buttonIndex == 1)
{//相册
UIImagePickerController *aImgPickerCtrl = [[UIImagePickerControlleralloc] init];
aImgPickerCtrl.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
[aImgPickerCtrl setAllowsEditing:YES];
aImgPickerCtrl.delegate = self;
}
}
#pragma mark - ImagePicker 代理方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YEScompletion:Nil];
UIImage *aImage = [infoobjectForKey:UIImagePickerControllerEditedImage];
// NSData *imageData = UIImagePNGRepresentation(aImage);
[imgBtnsetImage:aImage forState:UIControlStateNormal];
[imgBtnsetTitle:@" "forState:UIControlStateNormal];
}
@end
- iOS- 选择图片(相机/相册)
- iOS从相册 相机选择图片
- iOS 相册多选 相机选择图片
- 相机或相册选择图片
- ios中调用相机,相册,选择多张图片
- iOS学习:调用相机和相册,选择图片上传
- iOS调用系统相册和相机选择图片
- Android选择图片(从相册或相机)并裁剪
- iOS 图片的选择(包括相册和相机) 并且将图片转换成base64 的字符串
- 从相册(文档)或相机选择图片
- 打开系统相册/相机,选择图片
- 选择图片——相机与相册
- 从相册或相机选择图片
- 从相机或者相册选择图片
- 安卓相册,相机图片选择
- Android 相机或相册选择图片裁剪
- Android 调用相册或相机选择图片
- ios 单张图片上传(从相册或者相机)
- github发布开源项目代码教程
- ios 弹出键盘 顶端navigationbar 会上移
- shell实现多线程笔记
- pywebkitgtk的使用示例
- 对于机器视觉的应用的总结
- iOS- 选择图片(相机/相册)
- 编辑pdf内容
- Oracle学习之基本语法(一)—内置函数
- android 字符串工具类
- ES6学习——元数据(meta)编程:代理(Proxies)应用示例
- wampsever内置phpmyadmin密码修改和弹窗登陆
- 深入理解Java的接口和抽象类
- 【LCT】BZOJ 2631:tree
- SCOI2015 day1