iOS image upload and compression, Uiimagepickercontroller set Chinese

Source: Internet
Author: User

General effects

1. Add an agreement

<uiimagepickercontrollerdelegate, uinavigationcontrollerdelegate>

2. Add Uiimagepickercontroller

@property (nonatomic, strong) Uiimagepickercontroller *imagepick;           // for uploading pictures

3. Initialize Uiimagepickercontroller

Self.imagepick = [[Uiimagepickercontroller alloc]init];    Self.imagepick. delegate = self;

4. Frame Selection

//Select a picture in an album- (void) changeheadimageaction {Uialertcontroller*alert =[Uialertcontroller alertcontrollerwithtitle:nil message:nil Preferredstyle:uialertcontrollerstyleactionsheet]    ; //button: Select from album, type: Uialertactionstyledefault[Alert addaction:[uialertaction Actionwithtitle:@"Select from album"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];    }]]; //button: Photo, type: Uialertactionstyledefault[Alert addaction:[uialertaction Actionwithtitle:@"Take Pictures"Style:uialertactionstyledefault handler:^ (Uialertaction *_nonnull Action) {        if([Uiimagepickercontroller iscameradeviceavailable:uiimagepickercontrollercameradevicerear]) {Self.imagePi Ck.sourcetype=Uiimagepickercontrollersourcetypecamera;        [Self PresentViewController:self.imagePick animated:yes completion:nil]; }Else{NSLog (@"The camera doesn't seem to support ...");    }    }]]; //button: Cancel, type: Uialertactionstylecancel[Alert addaction:[uialertaction Actionwithtitle:@"Cancel"Style:uialertactionstylecancel handler:^ (Uialertaction *_nonnull Action)    {            }]]; [Self Presentviewcontroller:alert animated:yes completion:nil];}

5. Implementing the Protocol Approach

//Deselect Photos- (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]; //compress photos, this base64 is the image data that needs to be uploaded to the server[Image Drawinrect:cgrectmake (0,0, Max,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]; //set the title colorNsdictionary *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. Set the text in the album as Chinese characters

-(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;}

Then add the Chinese in the following location

iOS image upload and compression, Uiimagepickercontroller set Chinese

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.