self. Imageview = [[uiimageview alloc ]init];
self. Imageview. Frame = cgrectmake (30 , Titlelabel. height+30self neirongview. Width-60170
self. ImageView. Contentmode=uiviewcontentmodescaleaspectfit;
[self. ImageView setimagewithurl: [nsurl urlwithstring:_imageurl]];
[self. Neirongview addsubview:self. ImageView];
self. ImageView. Tag = 1234;
Self.imageView.backgroundColor =table_bgcolor;
self. ImageView. userinteractionenabled =YES;
uilongpressgesturerecognizer*longpress=[[uilongpressgesturerecognizer alloc] Initwithtarget:self action:@selector(ImageClick)];
// determine the time required for long-press gestures
Longpress. minimumpressduration = 1;
[self. ImageView addgesturerecognizer: longpress];
-(void) imageclick{
Uiimageview *myimageview = (uiimageview *) [self viewwithtag:1234];
uiimagewritetosavedphotosalbum(myimageview. Image, self, @selector(image:didFinshSavingWithError:contextInfo:), nil);
}
How to save a picture error prompt
-(void) Image: (UIImage *) image didfinshsavingwitherror: (nserror *) Error ContextInfo: ( void *) contextinfo
{
nsstring *mes = nil;
if (Error! = Nil) {
Mes = @ " save picture failed ";
} Else {
Mes = @ " Save picture Success ";
}
[self maketoast: mes];
[nstimer scheduledtimerwithtimeinterval:0.8f target:self Selector :@selector(fadeOut) userInfo:nil repeats:NO];
}
-(void) fadeout{
[UIView animatewithduration:. animations: ^{
self. Alpha = 0.0;
}Completion: ^ (BOOL finished) {
if (finished) {
[self removefromsuperview];
}
}];
}
How to save images to your phone by long-clicking a picture or QR code in iOS