diff --git a/SKPhotoBrowser/SKPhotoBrowser.bundle/images/btn_common_delete_wh.png b/SKPhotoBrowser/SKPhotoBrowser.bundle/images/btn_common_delete_wh.png new file mode 100644 index 0000000..5b1b65f Binary files /dev/null and b/SKPhotoBrowser/SKPhotoBrowser.bundle/images/btn_common_delete_wh.png differ diff --git a/SKPhotoBrowser/SKPhotoBrowser.bundle/images/btn_common_delete_wh@2x.png b/SKPhotoBrowser/SKPhotoBrowser.bundle/images/btn_common_delete_wh@2x.png new file mode 100644 index 0000000..4ac6f72 Binary files /dev/null and b/SKPhotoBrowser/SKPhotoBrowser.bundle/images/btn_common_delete_wh@2x.png differ diff --git a/SKPhotoBrowser/SKPhotoBrowser.bundle/images/btn_common_delete_wh@3x.png b/SKPhotoBrowser/SKPhotoBrowser.bundle/images/btn_common_delete_wh@3x.png new file mode 100644 index 0000000..600a84f Binary files /dev/null and b/SKPhotoBrowser/SKPhotoBrowser.bundle/images/btn_common_delete_wh@3x.png differ diff --git a/SKPhotoBrowser/SKPhotoBrowser.swift b/SKPhotoBrowser/SKPhotoBrowser.swift index 7bb42e6..e746a9f 100644 --- a/SKPhotoBrowser/SKPhotoBrowser.swift +++ b/SKPhotoBrowser/SKPhotoBrowser.swift @@ -14,6 +14,7 @@ import UIKit optional func willShowActionSheet(photoIndex: Int) optional func didDismissAtPageIndex(index: Int) optional func didDismissActionSheetWithButtonIndex(buttonIndex: Int, photoIndex: Int) + optional func didDeleted(notDeleted: [SKPhoto]) -> Void } public let SKPHOTO_LOADING_DID_END_NOTIFICATION = "photoLoadingDidEndNotification" @@ -39,7 +40,8 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate, UIActionShe public var displayBackAndForwardButton: Bool = true public var disableVerticalSwipe: Bool = false public var isForceStatusBarHidden: Bool = false - + public var displayDelete: Bool = false + // actions private var actionSheet: UIActionSheet! private var activityViewController: UIActivityViewController! @@ -58,6 +60,10 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate, UIActionShe private var doneButtonShowFrame: CGRect = CGRect(x: 5, y: 5, width: 44, height: 44) private var doneButtonHideFrame: CGRect = CGRect(x: 5, y: -20, width: 44, height: 44) + private var deleteButton: UIButton! + private var deleteButtonShowFrame: CGRect = CGRect(x: UIScreen.mainScreen().bounds.size.width - 60, y: 5, width: 44, height: 44) + private var deleteButtonHideFrame: CGRect = CGRect(x: UIScreen.mainScreen().bounds.size.width - 60, y: -20, width: 44, height: 44) + // photo's paging private var visiblePages: Set = Set() private var initialPageIndex: Int = 0 @@ -213,6 +219,19 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate, UIActionShe doneButton.alpha = 0.0 view.addSubview(doneButton) + // delete + let deleteImage = UIImage(named: "SKPhotoBrowser.bundle/images/btn_common_delete_wh", inBundle: bundle, compatibleWithTraitCollection: nil) ?? UIImage() + deleteButton = UIButton(type: UIButtonType.Custom) + deleteButton.setImage(deleteImage, forState: UIControlState.Normal) + deleteButton.frame = deleteButtonHideFrame + deleteButton.imageEdgeInsets = UIEdgeInsetsMake(15.25, 15.25, 15.25, 15.25) + deleteButton.backgroundColor = .clearColor() + deleteButton.addTarget(self, action: "deleteButtonPressed:", forControlEvents: UIControlEvents.TouchUpInside) + deleteButton.alpha = 0.0 + if displayDelete { + view.addSubview(deleteButton) + } + // action button toolActionButton = UIBarButtonItem(barButtonSystemItem: .Action, target: self, action: "actionButtonPressed") toolActionButton.tintColor = .whiteColor() @@ -602,6 +621,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate, UIActionShe prepareForClosePhotoBrowser() dismissViewControllerAnimated(true) { self.delegate?.didDismissAtPageIndex?(self.currentPageIndex) + self.delegate?.didDeleted?(self.photos as! [SKPhoto]) } } @@ -820,6 +840,16 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate, UIActionShe } } + // MARK: - Button + public func deleteButtonPressed(sender: UIButton) { + photos.removeAtIndex(currentPageIndex) + if photos.count == 0 { + dismissPhotoBrowser() + } else { + reloadData() + } + } + // MARK: Action Button public func actionButtonPressed() { let photo = photoAtIndex(currentPageIndex)