iOS調(diào)用系統(tǒng)相冊顯示英文標(biāo)題:
在 Info.plist 中
Localized resources can be mixed 設(shè)為 YES壁熄,意思是允許應(yīng)用獲取框架庫內(nèi)語言跪楞。
Localization native development region 設(shè)為 China
在inof.pilst中的設(shè)置
Privacy - Photo Library Additions Usage Description 保存圖片到相冊
Privacy - Photo Library Usage Description App需要您的同意,才能訪問相冊
Privacy - Camera Usage Description App需要您的同意,才能訪問相機(jī)
代碼部分
#import "ViewController.h"
#define kScreenHeight [[UIScreen mainScreen] bounds].size.height
// 獲取屏幕寬度 即:整屏的寬度
#define kScreenWidth [[UIScreen mainScreen] bounds].size.width
@interface ViewController ()<UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>
@property(nonatomic,strong)UIButton * positiveButton;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"首頁";
self.automaticallyAdjustsScrollViewInsets= NO;
[self creatMainView];
}
- (void)creatMainView{
_positiveButton = [UIButton buttonWithType:UIButtonTypeCustom];
_positiveButton.frame = CGRectMake((kScreenWidth-320)/2, 80, 320, 185);
[_positiveButton setImage:[UIImage imageNamed:@"身份證正面"] forState:UIControlStateNormal];
_positiveButton.backgroundColor = [UIColor grayColor];
[_positiveButton addTarget:self action:@selector(positiveButtonClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_positiveButton];
}
- (void)positiveButtonClick{
NSLog(@"正面照片");
UIActionSheet * actionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"相機(jī)",@"從相冊選擇", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"buttonIndex-----%li",(long)buttonIndex);
if (buttonIndex==0) {
NSLog(@"拍照");
[self openCamera];
}else if (buttonIndex==1){
NSLog(@"從相冊選擇");
[self openPhotoLibrary];
}
}
/*** 調(diào)用照相機(jī) */
- (void)openCamera{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES; //可編輯
//判斷是否可以打開照相機(jī)
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
//攝像頭
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:nil];
}else{
NSLog(@"沒有攝像頭");
}
}
/*** 打開相冊 */
-(void)openPhotoLibrary{
// 進(jìn)入相冊
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:YES completion:^{
NSLog(@"打開相冊");
}];
}else{
NSLog(@"不能打開相冊");
}
}
#pragma mark - UIImagePickerControllerDelegate
// 拍照完成回調(diào)
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id> *)info{
UIImage *image = info[@"UIImagePickerControllerOriginalImage"];
NSLog(@"finish..");
if(picker.sourceType == UIImagePickerControllerSourceTypeCamera){
//圖片存入相冊
[_positiveButton setImage:image forState:0];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}
if(picker.sourceType == UIImagePickerControllerSourceTypePhotoLibrary){
[_positiveButton setImage:image forState:0];
}
[self dismissViewControllerAnimated:YES completion:nil];
}
//進(jìn)入拍攝頁面點(diǎn)擊取消按鈕
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end