mwaterfall / MWPhotoBrowser

A simple iOS photo and video browser with grid view, captions and selections.
MIT License
8.75k stars 2.71k forks source link

How to put a delete button along with share button like native Photos app #367

Open RajChanchal opened 9 years ago

RajChanchal commented 9 years ago

Hi, How can I make the MWPhotoBrowser to look like native Photos app browser. I wanted to put the delete and share button at bottom, I don't need 'Edit' button though. Is there any way or code you might already have implemented? Or can you help implementing it?

fparkar commented 9 years ago

STOP SPAMMING THIS TOOL...

This tool is for showing images as gallery ONLY.

What you want is can be done, but you have to put efforts.

What you want is TOTALLY additional FEATURES.

KKKKaras commented 9 years ago

i solve it . by add a delegate.

RajChanchal commented 9 years ago

@KKKKaras , I stopped working on the tool for a moment. Could you share the code, it will be helpful in future or send pull request.

KKKKaras commented 9 years ago

@RajChanchal ok~ im a novice.

I add the method at the MWPhotoBrowserDelegate ( in the MWPhotoBrowser.h)

then add this (MWPhotoBrowser.m) [_compileBtn addTarget:self action:@selector(delete:) forControlEvents:UIControlEventTouchUpInside]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_compileBtn];

pragma mark -补充删除-

-(void)delete:(id)sender { // user delegate [self.delegate deleteAnyPicture]; } ----------------------------when use -------------------------

_imgIndex=(unsigned long)index;// GET index }

-(void)deleteAnyPicture// delegate call this method { NSLog(@"you delete the %d photo",_imgIndex); [_mwPhotos removeObjectAtIndex:_imgIndex];

NSLog(@"%@",_imgData[_imgIndex]);
//判断删除了哪一张图片
[_ImgAndVedioData enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
    if([obj objectForKey:@"fullImage"]==_imgData[_imgIndex])
    {
        [_ImgAndVedioData removeObject:obj];
    }
}];
[browser reloadData];

} // the _imgIndex is int 。record photo‘s index that you choose。 my English is poor 。im sorry :(

RajChanchal commented 9 years ago

Thanks, I hope it will be helpful in future for anyone wanting this feature.

RajChanchal commented 9 years ago

@KKKKaras , For me, it was simple. I just used the already developed delegate method:

And yes, to show a 'trash' bin instead of 'share' button in bottom bar just change following line in MWPhotoBrowser.m file: _actionButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(actionButtonPressed:)];

and make it:

_actionButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(actionButtonPressed:)];

Then in the delegate class implement the actionButtonPressed method and delete the image from your array at the received index and call reloadData method of the browser.

KKKKaras commented 9 years ago

@RajChanchal yes good job!~~

Esqarrouth commented 8 years ago

Heres my version in swift:

https://github.com/mwaterfall/MWPhotoBrowser/issues/239#issuecomment-152324938

badalpub1991 commented 8 years ago

Can anybody make example with this ? so, Other user can implement it in their project. Because delete is also one of the main functionality For such type of awesome control.

dblapps commented 7 years ago

Here's another way to change the appearance of the action button, without subclassing or making changes in MVPhotoBrowser. In case anybody finds it useful.

MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];

// Set options ...

// Present on navigation controller
[navigationController pushViewController:navigationController animated:YES];

// Replace the action button with a trash button
UIToolbar* toolbar = (UIToolbar*)[browser.view subviewOfClass:[UIToolbar class]];
UIBarButtonItem* originalActionButton = toolbar.items.lastObject;
UIBarButtonItem* newActionButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:originalActionButton.target action:originalActionButton.action];
NSMutableArray* items = [toolbar.items mutableCopy];
[items removeObject:originalActionButton];
[items addObject:newActionButton];
toolbar.items = [items copy];

Note that subviewOfClass: is just a method in a UIView extension that scans through the tree of subviews in a view looking for the first instance of a particular class.

A little hackish, but works well.