Skip to content
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
4 changes: 4 additions & 0 deletions Example/PullToRefreshSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -32,6 +33,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
590300831F1BE23A00A0894A /* custompulltorefresharrow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = custompulltorefresharrow.png; sourceTree = "<group>"; };
8C37CA271A3E815D00B3EFD4 /* pulltorefresharrow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = pulltorefresharrow.png; path = ../../Source/pulltorefresharrow.png; sourceTree = "<group>"; };
8C37CA281A3E815D00B3EFD4 /* PullToRefreshOption.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PullToRefreshOption.swift; sourceTree = "<group>"; };
8C37CA291A3E815D00B3EFD4 /* PullToRefreshView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PullToRefreshView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -109,6 +111,7 @@
C53BEC491A357BCA008A4302 /* Images.xcassets */,
C53BEC4B1A357BCA008A4302 /* LaunchScreen.xib */,
C53BEC411A357BCA008A4302 /* PullToRefreshSwift.xcdatamodeld */,
590300831F1BE23A00A0894A /* custompulltorefresharrow.png */,
C53BEC3D1A357BCA008A4302 /* Supporting Files */,
);
path = PullToRefreshSwift;
Expand Down Expand Up @@ -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 */,
);
Expand Down
8 changes: 4 additions & 4 deletions Example/PullToRefreshSwift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ 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()
self?.tableView.reloadData()
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()
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 9 additions & 7 deletions Source/PullToRefreshOption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
7 changes: 5 additions & 2 deletions Source/PullToRefreshView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down