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

Add margin and cornerRadius to item #310

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
15 changes: 6 additions & 9 deletions Example/ImageSlideshow.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,13 @@
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
DevelopmentTeam = 5VWB99DS38;
};
607FACE41AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
DevelopmentTeam = 5VWB99DS38;
TestTargetID = 607FACCF1AFB9204008FA782;
};
D0E8A9E11D97EB6D007EC517 = {
CreatedOnToolsVersion = 8.0;
DevelopmentTeam = 9X4J83EL7M;
LastSwiftMigration = 0800;
ProvisioningStyle = Automatic;
};
Expand Down Expand Up @@ -599,7 +596,7 @@
baseConfigurationReference = FD45C56C18E7B8EC08371B86 /* Pods-ImageSlideshow_Example.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 5VWB99DS38;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = ImageSlideshow/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -614,7 +611,7 @@
baseConfigurationReference = 09417F1351C21E0DCE8667BE /* Pods-ImageSlideshow_Example.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 5VWB99DS38;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = ImageSlideshow/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -628,7 +625,7 @@
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
DEVELOPMENT_TEAM = 5VWB99DS38;
DEVELOPMENT_TEAM = "";
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
Expand All @@ -646,7 +643,7 @@
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
DEVELOPMENT_TEAM = 5VWB99DS38;
DEVELOPMENT_TEAM = "";
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
Expand All @@ -667,7 +664,7 @@
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = dwarf;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 9X4J83EL7M;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand Down Expand Up @@ -696,7 +693,7 @@
CODE_SIGN_IDENTITY = "";
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 9X4J83EL7M;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand Down
16 changes: 8 additions & 8 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ PODS:
- Alamofire (4.7.3)
- AlamofireImage (3.4.1):
- Alamofire (~> 4.7)
- ImageSlideshow (1.6.0):
- ImageSlideshow/Core (= 1.6.0)
- ImageSlideshow/AFURL (1.6.0):
- ImageSlideshow (1.7.0):
- ImageSlideshow/Core (= 1.7.0)
- ImageSlideshow/AFURL (1.7.0):
- AFNetworking (~> 3.0)
- ImageSlideshow/Core
- ImageSlideshow/Alamofire (1.6.0):
- ImageSlideshow/Alamofire (1.7.0):
- AlamofireImage (~> 3.0)
- ImageSlideshow/Core
- ImageSlideshow/Core (1.6.0)
- ImageSlideshow/Kingfisher (1.6.0):
- ImageSlideshow/Core (1.7.0)
- ImageSlideshow/Kingfisher (1.7.0):
- ImageSlideshow/Core
- Kingfisher (> 3.0)
- ImageSlideshow/SDWebImage (1.6.0):
- ImageSlideshow/SDWebImage (1.7.0):
- ImageSlideshow/Core
- SDWebImage (< 5.0, >= 3.7)
- Kingfisher (4.10.0)
Expand Down Expand Up @@ -60,7 +60,7 @@ SPEC CHECKSUMS:
AFNetworking: b6f891fdfaed196b46c7a83cf209e09697b94057
Alamofire: c7287b6e5d7da964a70935e5db17046b7fde6568
AlamofireImage: 78d67ccbb763d87ba44b21583d2153500a195630
ImageSlideshow: 17a44fe50c43779149f83c3e369a3d9701f06d65
ImageSlideshow: 1cff4e8faab322a6ea4d906ee6979beb44e43e10
Kingfisher: 43c4b802d8b5256cf1f4379e9cd10b329be6d3e2
SDWebImage: 624d6e296c69b244bcede364c72ae0430ac14681

Expand Down
20 changes: 20 additions & 0 deletions ImageSlideshow/Classes/Core/ImageSlideshow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,24 @@ 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
}

/// CornerRadius
open var itemCornerRadius: CGFloat = 0 {
didSet {
for view in slideshowItems {
view.cornerRadius = itemCornerRadius
}
}
}

/// Margin
open var itemMargin: CGSize = CGSize.zero {
didSet {
for view in slideshowItems {
view.margin = itemMargin
}
}
}

// MARK: - Life cycle

override public init(frame: CGRect) {
Expand Down Expand Up @@ -318,6 +336,8 @@ open class ImageSlideshow: UIView {
for image in scrollViewImages {
let item = ImageSlideshowItem(image: image, zoomEnabled: zoomEnabled, activityIndicator: activityIndicator?.create(), maximumScale: maximumScale)
item.imageView.contentMode = contentScaleMode
item.margin = itemMargin
item.cornerRadius = itemCornerRadius
slideshowItems.append(item)
scrollView.addSubview(item)
i += 1
Expand Down
16 changes: 15 additions & 1 deletion ImageSlideshow/Classes/Core/ImageSlideshowItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ open class ImageSlideshowItem: UIScrollView, UIScrollViewDelegate {
/// Maximum zoom scale
open var maximumScale: CGFloat = 2.0

/// Margin
open var margin: CGSize = CGSize.zero {
didSet {
setNeedsLayout()
}
}

/// CornerRadius
open var cornerRadius: CGFloat = 0 {
didSet {
imageView.layer.cornerRadius = cornerRadius
}
}

fileprivate var lastFrame = CGRect.zero
fileprivate var imageReleased = false
fileprivate var isLoading = false
Expand Down Expand Up @@ -95,7 +109,7 @@ open class ImageSlideshowItem: UIScrollView, UIScrollViewDelegate {
super.layoutSubviews()

if !zoomEnabled {
imageView.frame.size = frame.size
imageView.frame.size = CGSize(width: frame.size.width - margin.width * 2, height: frame.size.height - margin.height * 2)
} else if !isZoomed() {
imageView.frame.size = calculatePictureSize()
}
Expand Down