IOS-uiactionsheet simple use and call system album

Source: Internet
Author: User

ImplementationUiactionsheetdelegate

Uiactionsheet * menu = [[uiactionsheet
Alloc]


Initwithtitle :@""


Delegate: Self


Cancelbuttontitle: @ "cancel"


Destructivebuttontitle: Nil


Otherbuttontitles: @ "image album", @ "photo ",
Nil];

[Menu
Showinview: Self. View];

# Pragma mark uiactionsheet Method

-(Void) actionsheet :( uiactionsheet *) actionsheet clickedbuttonatindex :( nsinteger) buttonindex

{


If (buttonindex = 0 ){

[Self
Photoalbumr]; // image album

} Else
If (buttonindex = 1 ){

[Self
Photocamera]; // take a photo

} Else
If (buttonindex = 2 ){

}

[Actionsheet
Release];

}

Call the system album

ImplementationUiimagepickercontrollerdelegate

-(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: @ "the device does not support the photo taking function"


Delegate: Nil


Cancelbuttontitle: @ "OK"


Otherbuttontitles: Nil];

[Alert
Show];

[Alert
Release];

}

}

# Pragma mark uiimagepicker Method

-(Void) imagepickercontroller :( uiimagepickercontroller *) picker

Didfinishpickingimage :( uiimage *) Image

Editinginfo :( nsdictionary *) editinginfo

{

 
/*Store images under 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];

}

// Select

-(Void) imagepickercontrollerdidcancel :( uiimagepickercontroller *) picker

{

[Picker
Dismissmodalviewcontrolleranimated: Yes];

}

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.