Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

customizable labels #115

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -65,6 +66,7 @@

/* Begin PBXFileReference section */
2869905A1EAF382C005B3E3E /* ES.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ES.swift; sourceTree = "<group>"; };
28F0A8011FA7641000A0639F /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/Localizable.strings"; sourceTree = "<group>"; };
5A180DBD1E80112D00F9EE1A /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = "<group>"; };
5A180DBF1E80113B00F9EE1A /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
5A180DC01E80114200F9EE1A /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Localizable.strings"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -321,7 +323,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = "egg swift";
TargetAttributes = {
F690772C1D0D0AE300BE91FE = {
Expand All @@ -345,6 +347,7 @@
Base,
"zh-Hans",
"zh-Hant",
"pt-BR",
);
mainGroup = F69200031CDB9A530029EF47;
productRefGroup = F692000D1CDB9A530029EF47 /* Products */;
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -438,6 +442,7 @@
5A180DBD1E80112D00F9EE1A /* Base */,
5A180DBF1E80113B00F9EE1A /* zh-Hans */,
5A180DC01E80114200F9EE1A /* zh-Hant */,
28F0A8011FA7641000A0639F /* pt-BR */,
);
name = Localizable.strings;
path = Animator;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
Expand All @@ -36,6 +37,7 @@
buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 23 additions & 3 deletions Sources/Animator/ESRefreshFooterAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions Sources/Animator/ESRefreshHeaderAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions Sources/Animator/pt-BR.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -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";
33 changes: 32 additions & 1 deletion Sources/ESPullToRefresh.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 */ {
Expand Down