iOS调用系统相册
2015-08-17 17:43
525 查看
1.点击按钮触发事件,调用系统的相册
#pragma mark 点击事件
- (void)onClickCarmerButton
{
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"请选择照片的来源" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相册选择",@"拍照", nil];
[sheet showInView:self.view];
}
#pragma mark ActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIImagePickerController *imageVC = [[UIImagePickerController alloc] init];
imageVC.delegate = self;
if (buttonIndex == 0) {
imageVC.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}else if (buttonIndex == 1) {
imageVC.sourceType = UIImagePickerControllerSourceTypeCamera;
}else if (buttonIndex == 2) {
return;
}
[self presentViewController:imageVC animated:NO completion:nil];
}
#pragma mark - UIImagePickerController Delegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = info[UIImagePickerControllerOriginalImage];
// [self uploadImage:image];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
// bug fixes: UIIMagePickerController使用中偷换StatusBar颜色的问题
if ([navigationController isKindOfClass:[UIImagePickerController class]] &&
((UIImagePickerController *)navigationController).sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
}
[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
// [navigationController.navigationBar setTintColor:[UIColor whiteColor]];
}
以上代码只是大体步骤
#pragma mark 点击事件
- (void)onClickCarmerButton
{
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"请选择照片的来源" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相册选择",@"拍照", nil];
[sheet showInView:self.view];
}
#pragma mark ActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIImagePickerController *imageVC = [[UIImagePickerController alloc] init];
imageVC.delegate = self;
if (buttonIndex == 0) {
imageVC.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}else if (buttonIndex == 1) {
imageVC.sourceType = UIImagePickerControllerSourceTypeCamera;
}else if (buttonIndex == 2) {
return;
}
[self presentViewController:imageVC animated:NO completion:nil];
}
#pragma mark - UIImagePickerController Delegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = info[UIImagePickerControllerOriginalImage];
// [self uploadImage:image];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
// bug fixes: UIIMagePickerController使用中偷换StatusBar颜色的问题
if ([navigationController isKindOfClass:[UIImagePickerController class]] &&
((UIImagePickerController *)navigationController).sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
}
[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
// [navigationController.navigationBar setTintColor:[UIColor whiteColor]];
}
以上代码只是大体步骤
相关文章推荐
- IOS工程自动打包并发布脚本实现
- IOS 代码动态添加控件
- IOS 7+ 生成二维码图片
- 通过USB连接线ssh到iOS中
- iOS截取正六边形图片
- iOS已发布应用中对异常信息捕获和处理
- 苹果IOS开发者账号总结
- IOS 如何实现画虚线
- xamarin.ios Parse 模糊查询 查询
- 教你如何在iOS项目中设置各种字体
- 2014最新苹果开发者账号注册流程图解分享
- IOS 第三方支付的使用:支付宝
- iOS常见的格式输出类型
- ios 后退指定 跳转
- iOS 给任意一个view转换为image的方法封装
- iOS 文字属性
- iOS——常用开发工具
- iOS xcode 工程 项目 代码行数统计
- iOS开发 iOS8 分割线右移15像素 将其归零
- iOS SDK详解之IBInspectable和IB_DESIGNABLE-Storyboad动态刷新