diff --git a/ESPullToRefreshExample/ESPullToRefreshExample.xcodeproj/project.pbxproj b/ESPullToRefreshExample/ESPullToRefreshExample.xcodeproj/project.pbxproj index 9183687..9652d57 100644 --- a/ESPullToRefreshExample/ESPullToRefreshExample.xcodeproj/project.pbxproj +++ b/ESPullToRefreshExample/ESPullToRefreshExample.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 2869905B1EAF382C005B3E3E /* ES.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2869905A1EAF382C005B3E3E /* ES.swift */; }; + 28F0A8021FA76DA600A0639F /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 5A180DBE1E80112D00F9EE1A /* Localizable.strings */; }; 37A073BD1F26F476002EF10F /* ES.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2869905A1EAF382C005B3E3E /* ES.swift */; }; 5A180DBC1E80112D00F9EE1A /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 5A180DBE1E80112D00F9EE1A /* Localizable.strings */; }; F63613701CDD9CCD00AA9AF7 /* MTRefreshHeaderAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = F636136F1CDD9CCD00AA9AF7 /* MTRefreshHeaderAnimator.swift */; }; @@ -65,6 +66,7 @@ /* Begin PBXFileReference section */ 2869905A1EAF382C005B3E3E /* ES.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ES.swift; sourceTree = ""; }; + 28F0A8011FA7641000A0639F /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/Localizable.strings"; sourceTree = ""; }; 5A180DBD1E80112D00F9EE1A /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = ""; }; 5A180DBF1E80113B00F9EE1A /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = ""; }; 5A180DC01E80114200F9EE1A /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Localizable.strings"; sourceTree = ""; }; @@ -321,7 +323,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "egg swift"; TargetAttributes = { F690772C1D0D0AE300BE91FE = { @@ -345,6 +347,7 @@ Base, "zh-Hans", "zh-Hant", + "pt-BR", ); mainGroup = F69200031CDB9A530029EF47; productRefGroup = F692000D1CDB9A530029EF47 /* Products */; @@ -375,6 +378,7 @@ F6AB6EA61D6AF82100AC33BE /* ESRefreshTableViewCell.xib in Resources */, F69200171CDB9A530029EF47 /* Assets.xcassets in Resources */, F69200151CDB9A530029EF47 /* Main.storyboard in Resources */, + 28F0A8021FA76DA600A0639F /* Localizable.strings in Resources */, F66B80341D86BE36006DDD16 /* ListTableViewCell.xib in Resources */, F6AA6C411CDC80DD00723622 /* WebViewController.xib in Resources */, F6C5F2F71DD2C8C7001DEA80 /* ESPhotoTableViewCell.xib in Resources */, @@ -438,6 +442,7 @@ 5A180DBD1E80112D00F9EE1A /* Base */, 5A180DBF1E80113B00F9EE1A /* zh-Hans */, 5A180DC01E80114200F9EE1A /* zh-Hant */, + 28F0A8011FA7641000A0639F /* pt-BR */, ); name = Localizable.strings; path = Animator; @@ -465,7 +470,7 @@ F69077331D0D0AE300BE91FE /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -487,7 +492,7 @@ F69077341D0D0AE300BE91FE /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -516,14 +521,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -566,14 +577,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; diff --git a/ESPullToRefreshExample/ESPullToRefreshExample.xcodeproj/xcshareddata/xcschemes/ESPullToRefresh.xcscheme b/ESPullToRefreshExample/ESPullToRefreshExample.xcodeproj/xcshareddata/xcschemes/ESPullToRefresh.xcscheme index bba3e36..582fada 100644 --- a/ESPullToRefreshExample/ESPullToRefreshExample.xcodeproj/xcshareddata/xcschemes/ESPullToRefresh.xcscheme +++ b/ESPullToRefreshExample/ESPullToRefreshExample.xcodeproj/xcshareddata/xcschemes/ESPullToRefresh.xcscheme @@ -1,6 +1,6 @@ @@ -36,6 +37,7 @@ buildConfiguration = "Release" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/ESPullToRefreshExample/ESPullToRefreshExample/Custom/TextView/TextViewController.swift b/ESPullToRefreshExample/ESPullToRefreshExample/Custom/TextView/TextViewController.swift index fa821d6..03efd96 100644 --- a/ESPullToRefreshExample/ESPullToRefreshExample/Custom/TextView/TextViewController.swift +++ b/ESPullToRefreshExample/ESPullToRefreshExample/Custom/TextView/TextViewController.swift @@ -38,7 +38,7 @@ class TextViewController: UIViewController { style.lineSpacing = 0.0 style.firstLineHeadIndent = 10.0 style.alignment = .justified - self?.textView.attributedText = NSAttributedString.init(string: (self?.text1)!, attributes: [NSAttributedStringKey.paragraphStyle : style, NSAttributedStringKey.font: UIFont.init(name: "ChalkboardSE-Bold", size: 16.0)!, NSAttributedStringKey.foregroundColor: UIColor.init(white: 0.3, alpha: 1.0)]) + self?.textView.attributedText = NSAttributedString.init(string: self?.text1 ?? "", attributes: [NSAttributedStringKey.paragraphStyle : style, NSAttributedStringKey.font: UIFont.init(name: "ChalkboardSE-Bold", size: 16.0)!, NSAttributedStringKey.foregroundColor: UIColor.init(white: 0.3, alpha: 1.0)]) self?.textView.es.stopPullToRefresh() } } diff --git a/README.md b/README.md index ebe4cdb..404165a 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,28 @@ let expried = scrollView.espried // expired or not func es.removeRefreshHeader() func es.removeRefreshFooter() ``` +### Customizing header and footer texts +After adding pull to refresh / infinite scroll you can customize the labels with the following methods: + +``` swift +self.scrollView.es.addPullToRefresh { + //do something.. +} + +self.scrollView.es.customizeHeaderLoadingText(with: "Something different for your app!") +self.scrollView.es.customizeHeaderPullToRefreshText(with: "Something different for your app!") +self.scrollView.es.customizeHeaderReleaseToRefreshText(with: "Something different for your app!") + +self.scrollView.es.addInfiniteScrolling { + //do something... +} + +self.scrollView.es.customizeFooterLoadingText(with: "Something different for your app!") +self.scrollView.es.customizeFooterLoadingMoreText(with: "Something different for your app!") +self.scrollView.es.customizeFooterNoMoreDataText(with: "Something different for your app!") + +``` ## Contribution diff --git a/Sources/Animator/ESRefreshFooterAnimator.swift b/Sources/Animator/ESRefreshFooterAnimator.swift index 59e1a33..b0cd411 100644 --- a/Sources/Animator/ESRefreshFooterAnimator.swift +++ b/Sources/Animator/ESRefreshFooterAnimator.swift @@ -27,9 +27,29 @@ import UIKit open class ESRefreshFooterAnimator: UIView, ESRefreshProtocol, ESRefreshAnimatorProtocol { - open var loadingMoreDescription: String = NSLocalizedString("Loading more", comment: "") - open var noMoreDataDescription: String = NSLocalizedString("No more data", comment: "") - open var loadingDescription: String = NSLocalizedString("Loading...", comment: "") + open var loadingMoreDescription: String = NSLocalizedString("Loading more", comment: ""){ + didSet { + if loadingMoreDescription != oldValue { + titleLabel.text = loadingMoreDescription; + } + } + } + + open var noMoreDataDescription: String = NSLocalizedString("No more data", comment: ""){ + didSet { + if noMoreDataDescription != oldValue { + titleLabel.text = noMoreDataDescription; + } + } + } + + open var loadingDescription = NSLocalizedString("Loading...", comment: "") { + didSet { + if loadingDescription != oldValue { + titleLabel.text = loadingDescription; + } + } + } open var view: UIView { return self } open var duration: TimeInterval = 0.3 diff --git a/Sources/Animator/ESRefreshHeaderAnimator.swift b/Sources/Animator/ESRefreshHeaderAnimator.swift index b24c4a2..39965d6 100644 --- a/Sources/Animator/ESRefreshHeaderAnimator.swift +++ b/Sources/Animator/ESRefreshHeaderAnimator.swift @@ -36,8 +36,20 @@ open class ESRefreshHeaderAnimator: UIView, ESRefreshProtocol, ESRefreshAnimator } } } - open var releaseToRefreshDescription = NSLocalizedString("Release to refresh", comment: "") - open var loadingDescription = NSLocalizedString("Loading...", comment: "") + open var releaseToRefreshDescription = NSLocalizedString("Release to refresh", comment: "") { + didSet { + if pullToRefreshDescription != oldValue { + titleLabel.text = releaseToRefreshDescription; + } + } + } + open var loadingDescription = NSLocalizedString("Loading...", comment: "") { + didSet { + if loadingDescription != oldValue { + titleLabel.text = loadingDescription; + } + } + } open var view: UIView { return self } open var insets: UIEdgeInsets = UIEdgeInsets.zero diff --git a/Sources/Animator/pt-BR.lproj/Localizable.strings b/Sources/Animator/pt-BR.lproj/Localizable.strings new file mode 100644 index 0000000..4560c27 --- /dev/null +++ b/Sources/Animator/pt-BR.lproj/Localizable.strings @@ -0,0 +1,5 @@ +"Pull to refresh" = "Puxe para recarregar"; +"Release to refresh" = "Solte para recarregar"; +"Loading..." = "Carregando..."; +"Loading more" = "Carregando mais"; +"No more data" = "Não há mais dados"; diff --git a/Sources/ESPullToRefresh.swift b/Sources/ESPullToRefresh.swift index 29524e5..d96947a 100644 --- a/Sources/ESPullToRefresh.swift +++ b/Sources/ESPullToRefresh.swift @@ -145,7 +145,38 @@ public extension ES where Base: UIScrollView { public func stopLoadingMore() { self.base.footer?.stopRefreshing() } - + + // Customizing strings + + public func customizeHeaderLoadingText(with text: String) { + guard let animator = self.base.header?.animator as? ESRefreshHeaderAnimator else { return } + animator.loadingDescription = text + } + + public func customizeHeaderPullToRefreshText(with text: String) { + guard let animator = self.base.header?.animator as? ESRefreshHeaderAnimator else { return } + animator.pullToRefreshDescription = text + } + + public func customizeHeaderReleaseToRefreshText(with text: String) { + guard let animator = self.base.header?.animator as? ESRefreshHeaderAnimator else { return } + animator.releaseToRefreshDescription = text + } + + public func customizeFooterLoadingText(with text: String) { + guard let animator = self.base.footer?.animator as? ESRefreshFooterAnimator else { return } + animator.loadingDescription = text + } + + public func customizeFooterLoadingMoreText(with text: String) { + guard let animator = self.base.footer?.animator as? ESRefreshFooterAnimator else { return } + animator.loadingMoreDescription = text + } + + public func customizeFooterNoMoreDataText(with text: String) { + guard let animator = self.base.footer?.animator as? ESRefreshFooterAnimator else { return } + animator.noMoreDataDescription = text + } } public extension UIScrollView /* Date Manager */ {