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