From 27ebc13d908d3a4cb7f9a20bf4ea5ad763a1f247 Mon Sep 17 00:00:00 2001 From: EyreFree Date: Mon, 28 Jan 2019 17:47:29 +0800 Subject: [PATCH] Add margin and cornerRadius to item --- .../ImageSlideshow.xcodeproj/project.pbxproj | 15 ++++++-------- Example/Podfile.lock | 16 +++++++-------- .../Classes/Core/ImageSlideshow.swift | 20 +++++++++++++++++++ .../Classes/Core/ImageSlideshowItem.swift | 16 ++++++++++++++- 4 files changed, 49 insertions(+), 18 deletions(-) diff --git a/Example/ImageSlideshow.xcodeproj/project.pbxproj b/Example/ImageSlideshow.xcodeproj/project.pbxproj index 05fa9253..92131973 100644 --- a/Example/ImageSlideshow.xcodeproj/project.pbxproj +++ b/Example/ImageSlideshow.xcodeproj/project.pbxproj @@ -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; }; @@ -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"; @@ -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"; @@ -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", @@ -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"; @@ -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"; @@ -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"; diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 86a66871..7bbae474 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -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) @@ -60,7 +60,7 @@ SPEC CHECKSUMS: AFNetworking: b6f891fdfaed196b46c7a83cf209e09697b94057 Alamofire: c7287b6e5d7da964a70935e5db17046b7fde6568 AlamofireImage: 78d67ccbb763d87ba44b21583d2153500a195630 - ImageSlideshow: 17a44fe50c43779149f83c3e369a3d9701f06d65 + ImageSlideshow: 1cff4e8faab322a6ea4d906ee6979beb44e43e10 Kingfisher: 43c4b802d8b5256cf1f4379e9cd10b329be6d3e2 SDWebImage: 624d6e296c69b244bcede364c72ae0430ac14681 diff --git a/ImageSlideshow/Classes/Core/ImageSlideshow.swift b/ImageSlideshow/Classes/Core/ImageSlideshow.swift index 27e57386..da57f43a 100644 --- a/ImageSlideshow/Classes/Core/ImageSlideshow.swift +++ b/ImageSlideshow/Classes/Core/ImageSlideshow.swift @@ -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) { @@ -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 diff --git a/ImageSlideshow/Classes/Core/ImageSlideshowItem.swift b/ImageSlideshow/Classes/Core/ImageSlideshowItem.swift index 60e77b8b..0264ce31 100644 --- a/ImageSlideshow/Classes/Core/ImageSlideshowItem.swift +++ b/ImageSlideshow/Classes/Core/ImageSlideshowItem.swift @@ -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 @@ -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() }