@interface Oneviewcontroller () <uiimagepickercontrollerdelegate, uinavigationcontrollerdelegate>{
Uiimageview *imageview;
}
@end
@implementation Oneviewcontroller
-(void) Viewdidload {
[Super Viewdidload];
Self.view.backgroundColor = [Uicolor Yellowcolor];
Uiimageview inherited from UIView
ImageView = [[Uiimageview alloc] Initwithframe:cgrectmake (50, 50, 100, 150)];
Imageview.backgroundcolor = [Uicolor Graycolor];
[Self.view Addsubview:imageview];
UIButton *button = [UIButton buttonwithtype: (Uibuttontypecustom)];
Button.frame = CGRectMake (100, 200, 100, 100);
Button.layer.cornerRadius = 50;
[Button addtarget:self action: @selector (camera) forControlEvents: (UIControlEventTouchUpInside)];
[Button settitle:@ "Camera" forstate: (UIControlStateNormal)];
[Self.view Addsubview:button];
Button.backgroundcolor = [Uicolor Redcolor];
UIButton *mbutton = [UIButton buttonwithtype: (Uibuttontypecustom)];
Mbutton.frame = CGRectMake (50, 400, 100, 50);
[Mbutton addtarget:self Action: @selector (photo) forControlEvents: (UIControlEventTouchUpInside)];
Mbutton.backgroundcolor = [Uicolor Redcolor];
[Mbutton settitle:@ "album" Forstate: (UIControlStateNormal)];
[Self.view Addsubview:mbutton];
}
-(void) camera {
Judging whether the camera
BOOL Iscamera = [Uiimagepickercontroller iscameradeviceavailable: (uiimagepickercontrollercameradevicerear)];
Uiimagepickercontrollercameradevicerear Rear-facing camera
Front-facing camera Uiimagepickercontrollercameradevicefront
if (!iscamera) {
NSLog (@ "no rear camera");
Return
}
Uiimagepickercontroller *imagepicker = [[Uiimagepickercontroller alloc] init];
Imagepicker.sourcetype = Uiimagepickercontrollersourcetypecamera;
Imagepicker.delegate = self;
imagepicker.editing = yes;//camera photos are allowed to edit
[Self presentviewcontroller:imagepicker animated:yes completion:^{
}];
}
Pick up albums
-(void) Photo {
Uiimagepickercontroller *imagepicker = [[Uiimagepickercontroller alloc] init];
Imagepicker.sourcetype = uiimagepickercontrollersourcetypephotolibrary;
[Self presentviewcontroller:imagepicker animated:yes completion:^{
NSLog (@ "open System album");
}];
Imagepicker.delegate = self;
[Imagepicker release];
}
-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker didfinishpickingimage: (UIImage *) Image Editinginfo :(Nsdictionary *) Editinginfo {
Select album Photos
Imageview.image = image;
[Self Dismissviewcontrolleranimated:yes completion:^{
}];
}
-(void) didreceivememorywarning {
[Super didreceivememorywarning];
Dispose of any resources the can be recreated.
}
@end
Access albums, select pictures from albums