iOS-UIActionSheet的简单使用和调用系统相簿
来源:互联网 发布:淘宝店铺装修源码 编辑:程序博客网 时间:2024/05/16 09:04
实现UIActionSheetDelegate
UIActionSheet *menu = [[UIActionSheet alloc]
initWithTitle: @""
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"图库相册",@"拍照", nil];
[menu showInView:self.view];
# pragma mark UIActionSheet method
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex==0) {
[self photoalbumr];//图库相册
}else if(buttonIndex==1){
[self photocamera];//拍照
}else if(buttonIndex==2){
}
[actionSheet release];
}
调用系统的相簿
实现UIImagePickerControllerDelegate
-(void)photoalbumr{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker =
[[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
else {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Error accessing photo library"
message:@"Device does not support a photo library"
delegate:nil
cancelButtonTitle:@"Drat!"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
-(void)photocamera{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController* imagepicker = [[UIImagePickerController alloc] init];
imagepicker.delegate = self;
imagepicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagepicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
imagepicker.allowsEditing = YES;
[self presentModalViewController:imagepicker animated:YES];
}
else {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Sorry"
message:@"设备不支持拍照功能"
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
#pragma mark UIImagePicker method
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
/*将图片存储到document下
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"];
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:NO];
_imgName=@"savedImage.png";
self._imgFilePath=documentsDirectory;
*/
[addPhoto setBackgroundImage:image forState:UIControlStateNormal];
[picker dismissModalViewControllerAnimated:YES];
}
// 完成选取
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissModalViewControllerAnimated:YES];
}
- iOS-UIActionSheet的简单使用和调用系统相簿
- iOS-UIActionSheet的简单使用和调用系统相簿
- 使用UIactionSheet调用系统相簿并将图片存储到缓存中
- UIActionSheet的使用和系统相机的相关调用
- IOS获取系统相簿里的照片
- iOS UIActionSheet的使用
- ios--UIActionSheet的使用
- ios-UIActionSheet的使用
- [IOS]UIActionSheet的使用
- [IOS]UIActionSheet的使用
- iOS中UIActionSheet的使用
- iOS之UIActionSheet的使用
- iOS中UIActionSheet的使用
- iOS中UIActionSheet的使用
- ios-获取系统相簿里边的所有照片
- ios-获取系统相簿里边的所有照片
- ios-获取系统相簿里边的所有照片
- ios-获取系统相簿里边的所有照片
- main.c(32): warning: #1-D: last line of file ends without a newline
- telnet命令检测端口
- ios面试题(C语言)
- 编程之美系列之二——寻找出现频率超过一半的数
- iOS KVO & KVC
- iOS-UIActionSheet的简单使用和调用系统相簿
- SEO优化解析www的域名好还是不带www的好
- shell man文件使用
- Oracle数据库12c新特性:高性能与高可用性
- LINUX需要掌握的基础知识(不断更新)
- 使用xampps的童鞋Access denied for user 'root'@'localhost' (using password: NO)的解决办法
- hdu-1011- Starship Troopers-自由树转二叉树+树形DP
- php中glob();函数用户加载核心类或者配置文件
- c语言快速排序法