diff --git a/README.md b/README.md index 75cff41..76fed69 100644 --- a/README.md +++ b/README.md @@ -107,14 +107,39 @@ func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath i You can customize Toolbar via SKPhotoBrowserOptions. ```swift -SKPhotoBrowserOptions.displayToolbar = false // all tool bar will be hidden -SKPhotoBrowserOptions.displayCounterLabel = false // counter label will be hidden -SKPhotoBrowserOptions.displayBackAndForwardButton = false // back / forward button will be hidden -SKPhotoBrowserOptions.displayAction = false // action button will be hidden -SKPhotoBrowserOptions.displayDeleteButton = true // delete button will be shown +SKPhotoBrowserOptions.displayToolbar = false // all tool bar will be hidden +SKPhotoBrowserOptions.displayCounterLabel = false // counter label will be hidden +SKPhotoBrowserOptions.displayBackAndForwardButton = false // back / forward button will be hidden +SKPhotoBrowserOptions.displayAction = false // action button will be hidden +SKPhotoBrowserOptions.displayDeleteButton = true // delete button will be shown +SKPhotoBrowserOptions.displayHorizontalScrollIndicator = false // horizontal scroll bar will be hidden +SKPhotoBrowserOptions.displayVerticalScrollIndicator = false // vertical scroll bar will be hidden let browser = SKPhotoBrowser(originImage: originImage, photos: images, animatedFromView: cell) ``` +#### Colors +You can customize text, icon and background colors via SKPhotoBrowserOptions +```swift +SKPhotoBrowserOptions.backgroundColor = UIColor.whiteColor() // browser view will be white +SKPhotoBrowserOptions.textAndIconColor = UIColor.blackColor() // text and icons will be black +SKPhotoBrowserOptions.toolbarTextShadowColor = UIColor.clearColor() // shadow of toolbar text will be removed +SKPhotoBrowserOptions.toolbarFont = UIFont(name: "Futura", size: 16.0) // font of toolbar will be 'Futura' +SKPhotoBrowserOptions.captionFont = UIFont(name: "Helvetica", size: 18.0) // font of toolbar will be 'Helvetica' +``` + +#### Images +You can customize the padding of displayed images via SKPhotoBrowserOptions +```swift +SKPhotoBrowserOptions.imagePaddingX = 50 // image padding left and right will be 25 +SKPhotoBrowserOptions.imagePaddingY = 50 // image padding top and bottom will be 25 +``` + +#### Statusbar +You can customize the visibility of the Statusbar in browser view via SKPhotoBrowserOptions +```swift +SKPhotoBrowserOptions.displayStatusbar = false // status bar will be hidden +``` + #### Custom Cache From Web URL You can use SKCacheable protocol if others are adaptable. (SKImageCacheable or SKRequestResponseCacheable) diff --git a/SKPhotoBrowser/SKAnimator.swift b/SKPhotoBrowser/SKAnimator.swift index 5c351c6..3bdf927 100644 --- a/SKPhotoBrowser/SKAnimator.swift +++ b/SKPhotoBrowser/SKAnimator.swift @@ -157,6 +157,8 @@ private extension SKAnimator { self.resizableImageView?.frame = self.finalImageViewFrame }, completion: { (Bool) -> Void in + UIApplication.sharedApplication().setStatusBarHidden(!SKPhotoBrowserOptions.displayStatusbar, withAnimation: .Fade) + browser.view.hidden = false browser.view.alpha = 1.0 browser.backgroundView.hidden = true diff --git a/SKPhotoBrowser/SKButtons.swift b/SKPhotoBrowser/SKButtons.swift index 25ecc37..3d95078 100644 --- a/SKPhotoBrowser/SKButtons.swift +++ b/SKPhotoBrowser/SKButtons.swift @@ -27,13 +27,14 @@ class SKButton: UIButton { func setup(imageName: String) { backgroundColor = .clearColor() + tintColor = SKPhotoBrowserOptions.textAndIconColor imageEdgeInsets = insets // clipsToBounds = true translatesAutoresizingMaskIntoConstraints = true autoresizingMask = [.FlexibleBottomMargin, .FlexibleLeftMargin, .FlexibleRightMargin, .FlexibleTopMargin] let image = UIImage(named: "SKPhotoBrowser.bundle/images/\(imageName)", - inBundle: bundle, compatibleWithTraitCollection: nil) ?? UIImage() + inBundle: bundle, compatibleWithTraitCollection: nil)?.imageWithRenderingMode(.AlwaysTemplate) ?? UIImage() setImage(image, forState: .Normal) } diff --git a/SKPhotoBrowser/SKCaptionView.swift b/SKPhotoBrowser/SKCaptionView.swift index f5ccbf5..d548a7f 100644 --- a/SKPhotoBrowser/SKCaptionView.swift +++ b/SKPhotoBrowser/SKCaptionView.swift @@ -61,13 +61,13 @@ private extension SKCaptionView { photoLabel.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] photoLabel.opaque = false photoLabel.backgroundColor = .clearColor() - photoLabel.textColor = .whiteColor() + photoLabel.textColor = SKPhotoBrowserOptions.textAndIconColor photoLabel.textAlignment = .Center photoLabel.lineBreakMode = .ByTruncatingTail photoLabel.numberOfLines = 3 photoLabel.shadowColor = UIColor(white: 0.0, alpha: 0.5) photoLabel.shadowOffset = CGSize(width: 0.0, height: 1.0) - photoLabel.font = UIFont.systemFontOfSize(17.0) + photoLabel.font = SKPhotoBrowserOptions.captionFont photoLabel.text = photo?.caption addSubview(photoLabel) } diff --git a/SKPhotoBrowser/SKIndicatorView.swift b/SKPhotoBrowser/SKIndicatorView.swift index 2f5b2b1..43236a1 100644 --- a/SKPhotoBrowser/SKIndicatorView.swift +++ b/SKPhotoBrowser/SKIndicatorView.swift @@ -16,6 +16,6 @@ class SKIndicatorView: UIActivityIndicatorView { override init(frame: CGRect) { super.init(frame: frame) center = CGPoint(x: frame.width / 2, y: frame.height / 2) - activityIndicatorViewStyle = .WhiteLarge + activityIndicatorViewStyle = SKPhotoBrowserOptions.backgroundColor.isEqual(UIColor.whiteColor()) ? .Gray : .WhiteLarge } } diff --git a/SKPhotoBrowser/SKPagingScrollView.swift b/SKPhotoBrowser/SKPagingScrollView.swift index b34e854..038f3cb 100644 --- a/SKPhotoBrowser/SKPagingScrollView.swift +++ b/SKPhotoBrowser/SKPagingScrollView.swift @@ -28,8 +28,8 @@ class SKPagingScrollView: UIScrollView { super.init(frame: frame) pagingEnabled = true - showsHorizontalScrollIndicator = true - showsVerticalScrollIndicator = true + showsHorizontalScrollIndicator = SKPhotoBrowserOptions.displayHorizontalScrollIndicator + showsVerticalScrollIndicator = SKPhotoBrowserOptions.displayHorizontalScrollIndicator } convenience init(frame: CGRect, browser: SKPhotoBrowser) { diff --git a/SKPhotoBrowser/SKPhotoBrowser.swift b/SKPhotoBrowser/SKPhotoBrowser.swift index 70b4d68..e8bb6c5 100644 --- a/SKPhotoBrowser/SKPhotoBrowser.swift +++ b/SKPhotoBrowser/SKPhotoBrowser.swift @@ -52,6 +52,10 @@ public class SKPhotoBrowser: UIViewController { var numberOfPhotos: Int { return photos.count } + + // statusbar initial state + private var statusbarHidden: Bool = UIApplication.sharedApplication().statusBarHidden + // MARK - Initializer required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) @@ -194,6 +198,7 @@ public class SKPhotoBrowser: UIViewController { } public func prepareForClosePhotoBrowser() { + UIApplication.sharedApplication().setStatusBarHidden(statusbarHidden, withAnimation: .None) cancelControlHiding() applicationWindow.removeGestureRecognizer(panGesture) NSObject.cancelPreviousPerformRequestsWithTarget(self) @@ -440,7 +445,7 @@ internal extension SKPhotoBrowser { ? zoomingScrollView.center.y - viewHalfHeight : -(zoomingScrollView.center.y - viewHalfHeight)) / viewHalfHeight - view.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(max(0.7, offset)) + view.backgroundColor = SKPhotoBrowserOptions.backgroundColor.colorWithAlphaComponent(max(0.7, offset)) // gesture end if sender.state == .Ended { @@ -464,7 +469,7 @@ internal extension SKPhotoBrowser { UIView.beginAnimations(nil, context: nil) UIView.setAnimationDuration(animationDuration) UIView.setAnimationCurve(UIViewAnimationCurve.EaseIn) - view.backgroundColor = UIColor.blackColor() + view.backgroundColor = SKPhotoBrowserOptions.backgroundColor zoomingScrollView.center = CGPoint(x: finalX, y: finalY) UIView.commitAnimations() } @@ -521,12 +526,12 @@ internal extension SKPhotoBrowser { // MARK: - Private Function private extension SKPhotoBrowser { func configureAppearance() { - view.backgroundColor = .blackColor() + view.backgroundColor = SKPhotoBrowserOptions.backgroundColor view.clipsToBounds = true view.opaque = false backgroundView = UIView(frame: CGRect(x: 0, y: 0, width: SKMesurement.screenWidth, height: SKMesurement.screenHeight)) - backgroundView.backgroundColor = .blackColor() + backgroundView.backgroundColor = SKPhotoBrowserOptions.backgroundColor backgroundView.alpha = 0.0 applicationWindow.addSubview(backgroundView) diff --git a/SKPhotoBrowser/SKPhotoBrowserOptions.swift b/SKPhotoBrowser/SKPhotoBrowserOptions.swift index 7fdd1d2..b6d7901 100644 --- a/SKPhotoBrowser/SKPhotoBrowserOptions.swift +++ b/SKPhotoBrowser/SKPhotoBrowserOptions.swift @@ -6,9 +6,11 @@ // Copyright © 2016年 suzuki_keishi. All rights reserved. // -import Foundation +import UIKit public struct SKPhotoBrowserOptions { + public static var displayStatusbar: Bool = false + public static var displayAction: Bool = true public static var shareExtraCaption: String? = nil public static var actionButtonTitles: [String]? @@ -18,10 +20,23 @@ public struct SKPhotoBrowserOptions { public static var displayBackAndForwardButton: Bool = true public static var disableVerticalSwipe: Bool = false - public static var displayCloseButton = true - public static var displayDeleteButton = false + public static var displayCloseButton: Bool = true + public static var displayDeleteButton: Bool = false - public static var bounceAnimation = false - public static var enableZoomBlackArea = true - public static var enableSingleTapDismiss = false + public static var displayHorizontalScrollIndicator: Bool = true + public static var displayVerticalScrollIndicator: Bool = true + + public static var bounceAnimation: Bool = false + public static var enableZoomBlackArea: Bool = true + public static var enableSingleTapDismiss: Bool = false + + public static var imagePaddingX: CGFloat = 0 + public static var imagePaddingY: CGFloat = 0 + + public static var backgroundColor = UIColor.blackColor() + public static var textAndIconColor = UIColor.whiteColor() + public static var toolbarTextShadowColor = UIColor.darkTextColor() + + public static var toolbarFont = UIFont(name: "Helvetica", size: 16.0) + public static var captionFont = UIFont.systemFontOfSize(17.0) } \ No newline at end of file diff --git a/SKPhotoBrowser/SKToolbar.swift b/SKPhotoBrowser/SKToolbar.swift index c16cfc9..e8427ac 100644 --- a/SKPhotoBrowser/SKToolbar.swift +++ b/SKPhotoBrowser/SKToolbar.swift @@ -109,16 +109,16 @@ private extension SKToolbar { toolCounterLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 95, height: 40)) toolCounterLabel.textAlignment = .Center toolCounterLabel.backgroundColor = .clearColor() - toolCounterLabel.font = UIFont(name: "Helvetica", size: 16.0) - toolCounterLabel.textColor = .whiteColor() - toolCounterLabel.shadowColor = .darkTextColor() + toolCounterLabel.font = SKPhotoBrowserOptions.toolbarFont + toolCounterLabel.textColor = SKPhotoBrowserOptions.textAndIconColor + toolCounterLabel.shadowColor = SKPhotoBrowserOptions.toolbarTextShadowColor toolCounterLabel.shadowOffset = CGSize(width: 0.0, height: 1.0) toolCounterButton = UIBarButtonItem(customView: toolCounterLabel) } func setupActionButton() { toolActionButton = UIBarButtonItem(barButtonSystemItem: .Action, target: browser, action: #selector(SKPhotoBrowser.actionButtonPressed)) - toolActionButton.tintColor = .whiteColor() + toolActionButton.tintColor = SKPhotoBrowserOptions.textAndIconColor } } @@ -128,13 +128,14 @@ class SKToolbarButton: UIButton { func setup(imageName: String) { backgroundColor = .clearColor() + tintColor = SKPhotoBrowserOptions.textAndIconColor imageEdgeInsets = insets translatesAutoresizingMaskIntoConstraints = true autoresizingMask = [.FlexibleBottomMargin, .FlexibleLeftMargin, .FlexibleRightMargin, .FlexibleTopMargin] contentMode = .Center let image = UIImage(named: "SKPhotoBrowser.bundle/images/\(imageName)", - inBundle: bundle, compatibleWithTraitCollection: nil) ?? UIImage() + inBundle: bundle, compatibleWithTraitCollection: nil)?.imageWithRenderingMode(.AlwaysTemplate) ?? UIImage() setImage(image, forState: .Normal) } } diff --git a/SKPhotoBrowser/SKZoomingScrollView.swift b/SKPhotoBrowser/SKZoomingScrollView.swift index 9c7c0f9..4977349 100644 --- a/SKPhotoBrowser/SKZoomingScrollView.swift +++ b/SKPhotoBrowser/SKZoomingScrollView.swift @@ -48,7 +48,7 @@ public class SKZoomingScrollView: UIScrollView { // tap tapView = SKDetectingView(frame: bounds) tapView.delegate = self - tapView.backgroundColor = UIColor.clearColor() + tapView.backgroundColor = .clearColor() tapView.autoresizingMask = [.FlexibleHeight, .FlexibleWidth] addSubview(tapView) @@ -182,10 +182,23 @@ public class SKZoomingScrollView: UIScrollView { } if let image = photo.underlyingImage { + + // create padding + let width: CGFloat = image.size.width + SKPhotoBrowserOptions.imagePaddingX + let height: CGFloat = image.size.height + SKPhotoBrowserOptions.imagePaddingY; + UIGraphicsBeginImageContextWithOptions(CGSizeMake(width, height), false, 0.0); + let context: CGContextRef = UIGraphicsGetCurrentContext()!; + UIGraphicsPushContext(context); + let origin: CGPoint = CGPointMake((width - image.size.width) / 2, (height - image.size.height) / 2); + image.drawAtPoint(origin) + UIGraphicsPopContext(); + let imageWithPadding = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); // image - photoImageView.image = image + photoImageView.image = imageWithPadding photoImageView.contentMode = photo.contentMode + photoImageView.backgroundColor = SKPhotoBrowserOptions.backgroundColor var photoImageViewFrame = CGRect.zero photoImageViewFrame.origin = CGPoint.zero