diff --git a/Example/PullToRefreshSwift.xcodeproj/project.pbxproj b/Example/PullToRefreshSwift.xcodeproj/project.pbxproj index 826f753..2c52ce9 100644 --- a/Example/PullToRefreshSwift.xcodeproj/project.pbxproj +++ b/Example/PullToRefreshSwift.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 590300841F1BE23A00A0894A /* custompulltorefresharrow.png in Resources */ = {isa = PBXBuildFile; fileRef = 590300831F1BE23A00A0894A /* custompulltorefresharrow.png */; }; 8C37CA2B1A3E815D00B3EFD4 /* pulltorefresharrow.png in Resources */ = {isa = PBXBuildFile; fileRef = 8C37CA271A3E815D00B3EFD4 /* pulltorefresharrow.png */; }; 8C37CA2C1A3E815D00B3EFD4 /* PullToRefreshOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C37CA281A3E815D00B3EFD4 /* PullToRefreshOption.swift */; }; 8C37CA2D1A3E815D00B3EFD4 /* PullToRefreshView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C37CA291A3E815D00B3EFD4 /* PullToRefreshView.swift */; }; @@ -32,6 +33,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 590300831F1BE23A00A0894A /* custompulltorefresharrow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = custompulltorefresharrow.png; sourceTree = ""; }; 8C37CA271A3E815D00B3EFD4 /* pulltorefresharrow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = pulltorefresharrow.png; path = ../../Source/pulltorefresharrow.png; sourceTree = ""; }; 8C37CA281A3E815D00B3EFD4 /* PullToRefreshOption.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PullToRefreshOption.swift; sourceTree = ""; }; 8C37CA291A3E815D00B3EFD4 /* PullToRefreshView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PullToRefreshView.swift; sourceTree = ""; }; @@ -109,6 +111,7 @@ C53BEC491A357BCA008A4302 /* Images.xcassets */, C53BEC4B1A357BCA008A4302 /* LaunchScreen.xib */, C53BEC411A357BCA008A4302 /* PullToRefreshSwift.xcdatamodeld */, + 590300831F1BE23A00A0894A /* custompulltorefresharrow.png */, C53BEC3D1A357BCA008A4302 /* Supporting Files */, ); path = PullToRefreshSwift; @@ -233,6 +236,7 @@ files = ( C53BEC481A357BCA008A4302 /* Main.storyboard in Resources */, C53BEC4D1A357BCA008A4302 /* LaunchScreen.xib in Resources */, + 590300841F1BE23A00A0894A /* custompulltorefresharrow.png in Resources */, C53BEC4A1A357BCA008A4302 /* Images.xcassets in Resources */, 8C37CA2B1A3E815D00B3EFD4 /* pulltorefresharrow.png in Resources */, ); diff --git a/Example/PullToRefreshSwift/ViewController.swift b/Example/PullToRefreshSwift/ViewController.swift index daa8430..eb6c67f 100644 --- a/Example/PullToRefreshSwift/ViewController.swift +++ b/Example/PullToRefreshSwift/ViewController.swift @@ -21,7 +21,8 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega self.tableView.separatorColor = UIColor(red: 224/255, green: 224/255, blue: 224/255, alpha: 1.0) - self.tableView.addPullRefresh { [weak self] in + let pullOptions = PullToRefreshOption(arrowImage: UIImage(named: "custompulltorefresharrow")) + self.tableView.addPullRefresh(options: pullOptions) { [weak self] in // some code sleep(1) self?.texts.shuffle() @@ -29,9 +30,8 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega self?.tableView.stopPullRefreshEver() } - var options = PullToRefreshOption() - options.indicatorColor = .blue - self.tableView.addPushRefresh(options: options) { [weak self] in + let pushOptions = PullToRefreshOption(indicatorColor: .blue) + self.tableView.addPushRefresh(options: pushOptions) { [weak self] in // some code sleep(1) self?.texts.shuffle() diff --git a/Example/PullToRefreshSwift/custompulltorefresharrow.png b/Example/PullToRefreshSwift/custompulltorefresharrow.png new file mode 100755 index 0000000..1cc59de Binary files /dev/null and b/Example/PullToRefreshSwift/custompulltorefresharrow.png differ diff --git a/Source/PullToRefreshOption.swift b/Source/PullToRefreshOption.swift index 8956557..38812b5 100755 --- a/Source/PullToRefreshOption.swift +++ b/Source/PullToRefreshOption.swift @@ -11,21 +11,23 @@ struct PullToRefreshConst { static let pushTag = 811 static let alpha = true static let height: CGFloat = 80 - static let imageName: String = "pulltorefresharrow.png" + static let defaultImageName: String = "pulltorefresharrow.png" static let animationDuration: Double = 0.5 static let fixedTop = true // PullToRefreshView fixed Top } -public struct PullToRefreshOption { - public var backgroundColor: UIColor - public var indicatorColor: UIColor - public var autoStopTime: Double // 0 is not auto stop - public var fixedSectionHeader: Bool // Update the content inset for fixed section headers +public class PullToRefreshOption: NSObject { + private(set) var backgroundColor: UIColor + private(set) var indicatorColor: UIColor + private(set) var autoStopTime: Double // 0 is not auto stop + private(set) var fixedSectionHeader: Bool // Update the content inset for fixed section headers + private(set) var arrowImage: UIImage? - public init(backgroundColor: UIColor = .clear, indicatorColor: UIColor = .gray, autoStopTime: Double = 0, fixedSectionHeader: Bool = false) { + public init(backgroundColor: UIColor = .clear, indicatorColor: UIColor = .gray, autoStopTime: Double = 0, fixedSectionHeader: Bool = false, arrowImage: UIImage? = nil) { self.backgroundColor = backgroundColor self.indicatorColor = indicatorColor self.autoStopTime = autoStopTime self.fixedSectionHeader = fixedSectionHeader + self.arrowImage = arrowImage } } diff --git a/Source/PullToRefreshView.swift b/Source/PullToRefreshView.swift index 28658f7..7edf909 100755 --- a/Source/PullToRefreshView.swift +++ b/Source/PullToRefreshView.swift @@ -89,8 +89,11 @@ open class PullToRefreshView: UIView { self.arrow = UIImageView(frame: CGRect(x: 0, y: 0, width: 30, height: 30)) self.arrow.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin] - self.arrow.image = UIImage(named: PullToRefreshConst.imageName, in: Bundle(for: type(of: self)), compatibleWith: nil) - + if let arrowImage = options.arrowImage { + self.arrow.image = arrowImage + } else { + self.arrow.image = UIImage(named: PullToRefreshConst.defaultImageName, in: Bundle(for: type(of: self)), compatibleWith: nil) + } self.indicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray) self.indicator.bounds = self.arrow.bounds