Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use imageViewProvider to create imageView #369

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion ImageSlideshow/Classes/Core/ImageSlideshow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ open class ImageSlideshow: UIView {
return scrollView.frame.size.width > 0 ? Int(scrollView.contentOffset.x + scrollView.frame.size.width / 2) / Int(scrollView.frame.size.width) : 0
}

/// Provider that creates UIImageView for each slideshow item. By default just returns UIImageView().
open var imageViewProvider: () -> UIImageView = {
return UIImageView()
}

// MARK: - Life cycle

override public init(frame: CGRect) {
Expand Down Expand Up @@ -320,7 +325,13 @@ open class ImageSlideshow: UIView {

var i = 0
for image in scrollViewImages {
let item = ImageSlideshowItem(image: image, zoomEnabled: zoomEnabled, activityIndicator: activityIndicator?.create(), maximumScale: maximumScale)
let item = ImageSlideshowItem(
imageView: imageViewProvider(),
image: image,
zoomEnabled: zoomEnabled,
activityIndicator: activityIndicator?.create(),
maximumScale: maximumScale
)
item.imageView.contentMode = contentScaleMode
slideshowItems.append(item)
scrollView.addSubview(item)
Expand Down
5 changes: 3 additions & 2 deletions ImageSlideshow/Classes/Core/ImageSlideshowItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import UIKit
open class ImageSlideshowItem: UIScrollView, UIScrollViewDelegate {

/// Image view to hold the image
public let imageView = UIImageView()
public let imageView: UIImageView

/// Activity indicator shown during image loading, when nil there won't be shown any
public let activityIndicator: ActivityIndicatorView?
Expand Down Expand Up @@ -53,7 +53,8 @@ open class ImageSlideshowItem: UIScrollView, UIScrollViewDelegate {
- parameter image: Input Source to load the image
- parameter zoomEnabled: holds if it should be possible to zoom-in the image
*/
init(image: InputSource, zoomEnabled: Bool, activityIndicator: ActivityIndicatorView? = nil, maximumScale: CGFloat = 2.0) {
init(imageView: UIImageView, image: InputSource, zoomEnabled: Bool, activityIndicator: ActivityIndicatorView? = nil, maximumScale: CGFloat = 2.0) {
self.imageView = imageView
self.zoomEnabled = zoomEnabled
self.image = image
self.activityIndicator = activityIndicator
Expand Down