惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Latest
Security Latest
Know Your Adversary
Know Your Adversary
S
Schneier on Security
K
Kaspersky official blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Google DeepMind News
Google DeepMind News
Project Zero
Project Zero
Recorded Future
Recorded Future
T
The Blog of Author Tim Ferriss
P
Palo Alto Networks Blog
Engineering at Meta
Engineering at Meta
MyScale Blog
MyScale Blog
L
LINUX DO - 热门话题
The Register - Security
The Register - Security
B
Blog
V
Vulnerabilities – Threatpost
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
Cyberwarzone
Cyberwarzone
Latest news
Latest news
Webroot Blog
Webroot Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
CXSECURITY Database RSS Feed - CXSecurity.com
L
LINUX DO - 最新话题
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog RSS Feed
aimingoo的专栏
aimingoo的专栏
The GitHub Blog
The GitHub Blog
D
Docker
G
Google Developers Blog
T
Threatpost
F
Full Disclosure
Attack and Defense Labs
Attack and Defense Labs
L
Lohrmann on Cybersecurity
Application and Cybersecurity Blog
Application and Cybersecurity Blog
月光博客
月光博客
D
DataBreaches.Net
WordPress大学
WordPress大学
F
Fortinet All Blogs
S
Secure Thoughts
Y
Y Combinator Blog
博客园 - Franky
Scott Helme
Scott Helme
Apple Machine Learning Research
Apple Machine Learning Research
Hacker News: Ask HN
Hacker News: Ask HN
酷 壳 – CoolShell
酷 壳 – CoolShell
Cloudbric
Cloudbric
N
News | PayPal Newsroom

isaced

使用 TypeScript 构建的 appstore-connect-sdk 归档 我用 SwiftUI 写了一个 V2ex 客户端 Docker 容器化多应用部署 Swift Server-side SDWebImage 为什么无法读取 webpmux 生成的 WebP 动图? [译] 探索 Swift 4 中新的 String API 对一个 Django 站点做 ab 压力测试 fir-mac 开发笔记 iOS10 Safari 引导用户信任企业签名 Swift Web 开发之 Vapor - 模版 Leaf(三) Swift Web 开发之 Vapor - 路由(二) HoloLens 初体验 Swift Web 开发之 Vapor - 入门(一) Jenkins for iOS 搭建日记 iOS HOOK 注入与重签名 Xcode 使用 Configuration 来配置不同的项目环境 图床从SAE迁移到七牛 给 UIProgressView 脱掉那层微弱的渐变 初用 CocoaAsyncSocket 记一次 SQLite 性能优化 有多色 - 开发小记 海岛风情 - 泰国普吉岛六日游 EGOCache 源码解析 日语五十音假名临摹校验算法 [iOS] UITextView 追加文字自动跳到顶部解决方法 Cocoa 新的依赖管理工具:Carthage 新年快乐! 博客主机换到搬瓦工 写了个iOS小游戏:有多色 iOS 后台任务之 Long-running background task 悄悄的就必须用 XCode 5.1.1 上传了! HTTP Content-type 与 AFNetworking Objective-Cloud 初体验(1) 掌中站上架小记 NSLoger 上线了 Python Markdown 做语法限制 Nginx + Gunicorn + Django 部署小记 用Shell脚本批量裁剪App Icon各个尺寸 LaunchRocket使用小记 用宏提速NSCoding 2014新年伊始:近期读过的好文推荐 [iOS] stringWithFormat 和 initWithFormat 有何不同? Apache + Flask + mod_wsgi + Koding 部署小记 收集几个Objective-C的HTML解析库 NSMapTable: 不只是一个能放weak指针的 NSDictionary 2013,再见! Emlog到Typecho的迁移工具:emlog2typecho [iOS]代码推荐:大图缩放视图 - Vertigo iOS:hidesBottomBarWhenPushed的正确用法 Xcode 5新的Interface Builder,你准备好了吗? [翻译]如何使用Django创建简单的博客 我的Mac音乐播放器 初识 NSDataDetector Objective-C 计算代码运行时间 WordPress上传文件自动重命名 iOS:仿jing.fm的音乐播放视图 我的啃黑苹果之路 关于 搜索 项目
[iOS]给上拉下拉刷新PullToRefresh做本地化
2013-11-04 · via isaced

相信很多小朋友都做过下拉刷新,上拉加载更多,或者是点一下加载更多吧,我在几个项目中都用到了上拉下拉刷新,用的是[EGOTableViewPullRefresh],是我觉得同样给力的EGOCache同一个作者的作品。

这份代码有两年没更新了,惊奇的发现 Commit 记录在两天前有点动静,不过它确实挺好用,只是没有支持 Block:

EGOTableViewPullRefresh Commits

使用方法很简单,这里就不说了,今天的需求是要把提示信息改为中文,于是我翻了翻代码,写的很不错,所有提示文本都用的 NSLocalizedStringFromTable 来处理,如:

_statusLabel.text = NSLocalizedStringFromTable(@"Pull up to load more...", @"PullTableViewLan",@"Pull down to load more status");
stringWithFormat:NSLocalizedStringFromTable(@"Updated %ld minute ago",@"PullTableViewLan",@"Last uppdate in minutes singular"),(long)timeToDisplay];

这就很方便让我们把这些信息改为我们想要的文本,首先得说说 NSLocalizedStringFromTable,其实在我们做本地化中用的最多的应该是 NSLocalizedString 了,我们看看它的定义:

#define NSLocalizedString(key, comment) \ [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]

这是一个宏定义,其实是调用了 NSBundle 的 localizedStringForKey 方法,也就是在当前 Bundle 中查找资源文件名 Localizable.strings 中 key 所指向的字符串。那么 NSLocalizedStringFromTable 呢?我们再看看它的定义:

#define NSLocalizedStringFromTable(key, tbl, comment) \
	    [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:(tbl)]

可以看到这里的 table 参数已经不是 nil 了,而是你传进去的一个 strings 文件的文件名,EGOTableViewPullRefresh 所有的本地化操作都是传的 PullTableViewLan,也就是说它会在你的工程里找 PullTableViewLan.strings 文件来匹配本地化字符串。

那我们的做法就是在 EGOTableViewPullRefresh 的目录中新建 PullTableViewLan.strings 文件:

PullTableViewLan.strings

然后编辑文件,输入 EGOTableViewPullRefresh 定义的一些本地话字符串,我的是这样:

/*
  Localizable.strings

  Created by isaced on 13-8-6.
  Copyright (c) 2013年 isaced. All rights reserved.
*/

"Loading..." = "加载更多...";

"Pull down to refresh..." = "下拉刷新...";
"Release to refresh..." = "松开刷新...";

"Pull up to load more..." = "上拉加载更多...";
"Release to load more..." = "松开加载更多...";

"Updated %ld minute ago" = "%ld 分钟前更新";
"Updated %ld minutes ago" = "%ld 分钟前更新";

然后对比一下效果,怎么样,是不是不用修改一句代码就可以把原来的英文提示改为中文。

Pull Refresh

晕,整篇文章打字打“本地化”的时候总自动拼出“本地话”,郁闷!还推荐另一份代码:PullToRefresh