From 8fe8abdf70fb4278ad1e9be628ab43e7af9eb929 Mon Sep 17 00:00:00 2001 From: Christoph Linimayer Date: Sun, 16 Jul 2017 20:26:26 +0200 Subject: [PATCH] Adds possibility to use a custom arrow image --- .../project.pbxproj | 4 ++++ Example/PullToRefreshSwift/ViewController.swift | 8 ++++---- .../custompulltorefresharrow.png | Bin 0 -> 16246 bytes Source/PullToRefreshOption.swift | 16 +++++++++------- Source/PullToRefreshView.swift | 7 +++++-- 5 files changed, 22 insertions(+), 13 deletions(-) create mode 100755 Example/PullToRefreshSwift/custompulltorefresharrow.png 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 0000000000000000000000000000000000000000..1cc59de87f61fffdb3149cf454e3f7582f978b3f GIT binary patch literal 16246 zcmeI3c~BEs9>*IIY5-xzb!3oTofy_yQ9GT^K@LI?5)i~FAR_9b=_DQKA(u&z%h}Zt z3k8``x5j%!sTmI#4`dwAmCSm87P`7(m4a(UcSk`7b!OG|T(>)cBtAl~wKaciZFQ=W z&hLHS@B3bV-qG)$UYR+4N_c2=C1oPr@+zag?*x;-(wEn)Z3BXaWWd8%nrt=Y)IbY>0CDK%Qi+GKKKsRh#(;dYh=FCa__><7nM*epVq zz@9Bsaa9%tUPz>sTk)CY({r@tMOulDohT2Ll}bqiBW}l7rAC9vCM`{1yL_eOf2tT^ zvs_i|MG5RAszFwsDwCx!TXB|5%9W40C`s6-+`xIBc%gUK4Ot;}S{ zN@0^N#%q{aJsPLMsv1bmGqPA`VJVnG}%5Nc3Z!xv+)I8LL{@Fcia$n*5v zCw+jm61NhIa9yg^Y;-Lc3ud+9)Z|TI_s?F>3hSfln*LH^V4vQO=74l>pU4JeZdv!= zj@5v4ue*n|_m&4vmNddZO>L+N9(*jHE9^ zY<8bAZkxOph6PsCYFTt#MQUST(RNb+uN<*0izDyqIYWe z88%cR6$t)chRr>gZ!W_A6+Lj#Qv0z~VZ||WG3S`ghW|JP!TMg%UMpOQ*>T^cK>~KI zj()}-6L(F(LuJ+x`ZCaiGV0DtH<7Q&mXPnmPI{m}MZQbR(xzprAgFvC1T9$x zLC;>3*B%He=0eb2HTj0_1_=7VymrCqR0sA6Xemy?%@aCJA`(^hl{``gQ#y=_o*`H*D4#}VVn~M?O1Yp}j#Jf9R z2Ca1jKMc$Zj$9g~ZmmrU5(FL^GQy#9MrRf@*Tpyk-wV3Ew5~ICJX^YV{_wI`c2)g? zs)h&h(c0q9q?Q$@zFb_ryJFqwr(0IEPyJrdcqa3wtG(?v7dlryA3rNQ-jOeCty!0q z+!d^j-q1KC@7@CS^xB@v`}^!M4~In6OGgH#F0G7kHam)(p;z|oa}+xdjc~FaMjl=z zdNeAk?NA{a+J0?Ul{$d48x>s*_#HItRzi3~)A~nKKWjv`trxDT9s5g5)YBc2&ptgk z`b1v#i`$P!<~!221?FYEZjxu5B=YyiuBd%*I$=wu@{V!ylB$nl{$PuEch_rvOQFEl zyEC|InaCdp-QT86mf$?X){QSq#z0CzXFLE4X_!Ax|YF7NJ zJ5F=8?2p2hGwUMW*G|}ZFy#29S7{lw-(;*wX)^AZa`mUVN9r}~-fSKG`1S$#^u&N( zodtvE~lI4NUcG492}A%Z>#+ESu1Pn`M)&t{R?v1c>+GG&A7#E?@M_GmS}eNbNk&kxIQ;m@__NQ)P3t<7yEk}w`&aWE z+=r)Q_Md#Ft_k>d-4`EE_{)`s!<))CFOQBa`tU}O3Hq$zy(dkZnpbL~E3UClgkAqG zW!d4c%2-2Wdssj4oyoiRZ#*{cSjw1%v2{0U+9r={ocnd-4CVZlZEM0-PiZj2xa?@y z!3%+hxUXtwFU;Nbc=+WPvZ^!5@LwH0Q<2m69J10x#gpvgiFYTfL)K^f_^)tiQ)Soe UO%p3ys5j%&Q>H8TCaXXBH?X)&mjD0& literal 0 HcmV?d00001 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