ios 圖片上傳與壓縮,UIImagePickerController設定中文

來源:互聯網
上載者:User

標籤:make   with   err   animate   bar   key   apple   jpeg   return   

普通效果

 

 

1.添加協議

<UIImagePickerControllerDelegate, UINavigationControllerDelegate>

2.添加UIImagePickerController

@property (nonatomic, strong) UIImagePickerController *imagePick;           //用於上傳圖片

3.初始化UIImagePickerController

self.imagePick = [[UIImagePickerController alloc]init];    self.imagePick.delegate = self;

4.彈框選擇

//選取相簿內的圖片- (void)changeHeadImageAction {    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];    //按鈕:從相簿選擇,類型:UIAlertActionStyleDefault    [alert addAction:[UIAlertAction actionWithTitle:@"從相簿選擇" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {        self.imagePick.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;        //        imagePick.mediaTypes = @[(NSString *)kUTTypeImage];        self.imagePick.allowsEditing = YES;        [self presentViewController:self.imagePick animated:YES completion:nil];    }]];    //按鈕:拍照,類型:UIAlertActionStyleDefault    [alert addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {        if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) {            self.imagePick.sourceType = UIImagePickerControllerSourceTypeCamera;            [self presentViewController:self.imagePick animated:YES completion:nil];        }else{            NSLog(@"網路攝影機貌似不支援...");        }    }]];    //按鈕:取消,類型:UIAlertActionStyleCancel    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {            }]];    [self presentViewController:alert animated:YES completion:nil];}

5.實現協議方法

// 取消選擇照片- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{    [picker dismissViewControllerAnimated:YES completion:nil];}- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{        [picker dismissViewControllerAnimated:NO completion:nil];    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];    //壓縮照片,這個base64就是需要上傳到伺服器的圖片資料    [image drawInRect:CGRectMake(0, 0, 150, 266)];    NSData *data = UIImageJPEGRepresentation(image, 0.0f);    NSString *base64 = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];       }-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{    viewController.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];    viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];    //設定標題顏色    NSDictionary *dic=[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];    self.navigationController.navigationBar.titleTextAttributes = dic;}- (void)doCancel:(id)b {    NSLog(@"doCancel");    [self.imagePick dismissViewControllerAnimated:YES completion:nil];}

6.設定相簿裡面的文字為漢字

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{//    [NSUserDefaults standardUserDefaults] setObject:@"zh-Hans" forKey:NSLangu;        [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"zh-Hans", nil] forKey:@"AppleLanguages"];    [[NSUserDefaults standardUserDefaults] synchronize];    return YES;}

然後在下面這個位置添加中文

ios 圖片上傳與壓縮,UIImagePickerController設定中文

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.