Skip to content

Commit

Permalink
本地化+间距问题
Browse files Browse the repository at this point in the history
1.为了不受iOS获取语言字符串不稳定的影响,改为只处理3种本地化语言,其他按照系统默认做法
2.提供labelLeftInset属性用来调整文字和圈圈、箭头之间的间距
  • Loading branch information
MJ Lee authored and MJ Lee committed Jun 20, 2016
1 parent 76f979e commit 24008cf
Show file tree
Hide file tree
Showing 23 changed files with 82 additions and 54 deletions.
2 changes: 1 addition & 1 deletion MJRefresh.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'MJRefresh'
s.version = '3.1.7'
s.version = '3.1.8'
s.summary = 'An easy way to use pull-to-refresh'
s.homepage = 'https://github.com/CoderMJLee/MJRefresh'
s.license = 'MIT'
Expand Down
10 changes: 9 additions & 1 deletion MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ - (void)setImages:(NSArray *)images forState:(MJRefreshState)state
}

#pragma mark - 实现父类的方法
- (void)prepare
{
[super prepare];

// 初始化间距
self.labelLeftInset = 20;
}

- (void)placeSubviews
{
[super placeSubviews];
Expand All @@ -77,7 +85,7 @@ - (void)placeSubviews
self.gifView.contentMode = UIViewContentModeCenter;
} else {
self.gifView.contentMode = UIViewContentModeRight;
self.gifView.mj_w = self.mj_w * 0.5 - 20 - self.stateLabel.mj_textWith * 0.5;
self.gifView.mj_w = self.mj_w * 0.5 - self.labelLeftInset - self.stateLabel.mj_textWith * 0.5;
}
}

Expand Down
2 changes: 1 addition & 1 deletion MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ - (void)placeSubviews
// 圈圈
CGFloat loadingCenterX = self.mj_w * 0.5;
if (!self.isRefreshingTitleHidden) {
loadingCenterX -= self.stateLabel.mj_textWith * 0.5 + 20;
loadingCenterX -= self.stateLabel.mj_textWith * 0.5 + self.labelLeftInset;
}
CGFloat loadingCenterY = self.mj_h * 0.5;
self.loadingView.center = CGPointMake(loadingCenterX, loadingCenterY);
Expand Down
2 changes: 2 additions & 0 deletions MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#import "MJRefreshAutoFooter.h"

@interface MJRefreshAutoStateFooter : MJRefreshAutoFooter
/** 文字距离圈圈、箭头的距离 */
@property (assign, nonatomic) CGFloat labelLeftInset;
/** 显示刷新状态的label */
@property (weak, nonatomic, readonly) UILabel *stateLabel;

Expand Down
3 changes: 3 additions & 0 deletions MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ - (void)prepare
{
[super prepare];

// 初始化间距
self.labelLeftInset = MJRefreshLabelLeftInset;

// 初始化文字
[self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshAutoFooterIdleText] forState:MJRefreshStateIdle];
[self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshAutoFooterRefreshingText] forState:MJRefreshStateRefreshing];
Expand Down
10 changes: 9 additions & 1 deletion MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ - (void)setImages:(NSArray *)images forState:(MJRefreshState)state
}

#pragma mark - 实现父类的方法
- (void)prepare
{
[super prepare];

// 初始化间距
self.labelLeftInset = 20;
}

- (void)setPullingPercent:(CGFloat)pullingPercent
{
[super setPullingPercent:pullingPercent];
Expand All @@ -88,7 +96,7 @@ - (void)placeSubviews
self.gifView.contentMode = UIViewContentModeCenter;
} else {
self.gifView.contentMode = UIViewContentModeRight;
self.gifView.mj_w = self.mj_w * 0.5 - 20 - self.stateLabel.mj_textWith * 0.5;
self.gifView.mj_w = self.mj_w * 0.5 - self.labelLeftInset - self.stateLabel.mj_textWith * 0.5;
}
}

Expand Down
2 changes: 1 addition & 1 deletion MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ - (void)placeSubviews
// 箭头的中心点
CGFloat arrowCenterX = self.mj_w * 0.5;
if (!self.stateLabel.hidden) {
arrowCenterX -= 20 + self.stateLabel.mj_textWith * 0.5;
arrowCenterX -= self.labelLeftInset + self.stateLabel.mj_textWith * 0.5;
}
CGFloat arrowCenterY = self.mj_h * 0.5;
CGPoint arrowCenter = CGPointMake(arrowCenterX, arrowCenterY);
Expand Down
2 changes: 2 additions & 0 deletions MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#import "MJRefreshBackFooter.h"

@interface MJRefreshBackStateFooter : MJRefreshBackFooter
/** 文字距离圈圈、箭头的距离 */
@property (assign, nonatomic) CGFloat labelLeftInset;
/** 显示刷新状态的label */
@property (weak, nonatomic, readonly) UILabel *stateLabel;
/** 设置state状态下的文字 */
Expand Down
3 changes: 3 additions & 0 deletions MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ - (void)prepare
{
[super prepare];

// 初始化间距
self.labelLeftInset = MJRefreshLabelLeftInset;

// 初始化文字
[self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterIdleText] forState:MJRefreshStateIdle];
[self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterPullingText] forState:MJRefreshStatePulling];
Expand Down
17 changes: 16 additions & 1 deletion MJRefresh/Custom/Header/MJRefreshGifHeader.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ - (void)setImages:(NSArray *)images forState:(MJRefreshState)state
}

#pragma mark - 实现父类的方法
- (void)prepare
{
[super prepare];

// 初始化间距
self.labelLeftInset = 20;
}

- (void)setPullingPercent:(CGFloat)pullingPercent
{
[super setPullingPercent:pullingPercent];
Expand All @@ -90,7 +98,14 @@ - (void)placeSubviews
self.gifView.contentMode = UIViewContentModeCenter;
} else {
self.gifView.contentMode = UIViewContentModeRight;
self.gifView.mj_w = self.mj_w * 0.5 - 90;

CGFloat stateWidth = self.stateLabel.mj_textWith;
CGFloat timeWidth = 0.0;
if (!self.lastUpdatedTimeLabel.hidden) {
timeWidth = self.lastUpdatedTimeLabel.mj_textWith;
}
CGFloat textWidth = MAX(stateWidth, timeWidth);
self.gifView.mj_w = self.mj_w * 0.5 - textWidth * 0.5 - self.labelLeftInset;
}
}

Expand Down
3 changes: 1 addition & 2 deletions MJRefresh/Custom/Header/MJRefreshNormalHeader.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,13 @@ - (void)placeSubviews
// 箭头的中心点
CGFloat arrowCenterX = self.mj_w * 0.5;
if (!self.stateLabel.hidden) {
CGFloat offset = 20;
CGFloat stateWidth = self.stateLabel.mj_textWith;
CGFloat timeWidth = 0.0;
if (!self.lastUpdatedTimeLabel.hidden) {
timeWidth = self.lastUpdatedTimeLabel.mj_textWith;
}
CGFloat textWidth = MAX(stateWidth, timeWidth);
arrowCenterX -= textWidth / 2 + offset;
arrowCenterX -= textWidth / 2 + self.labelLeftInset;
}
CGFloat arrowCenterY = self.mj_h * 0.5;
CGPoint arrowCenter = CGPointMake(arrowCenterX, arrowCenterY);
Expand Down
2 changes: 2 additions & 0 deletions MJRefresh/Custom/Header/MJRefreshStateHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
@property (weak, nonatomic, readonly) UILabel *lastUpdatedTimeLabel;

#pragma mark - 状态相关
/** 文字距离圈圈、箭头的距离 */
@property (assign, nonatomic) CGFloat labelLeftInset;
/** 显示刷新状态的label */
@property (weak, nonatomic, readonly) UILabel *stateLabel;
/** 设置state状态下的文字 */
Expand Down
3 changes: 3 additions & 0 deletions MJRefresh/Custom/Header/MJRefreshStateHeader.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ - (void)prepare
{
[super prepare];

// 初始化间距
self.labelLeftInset = MJRefreshLabelLeftInset;

// 初始化文字
[self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshHeaderIdleText] forState:MJRefreshStateIdle];
[self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshHeaderPullingText] forState:MJRefreshStatePulling];
Expand Down
1 change: 1 addition & 0 deletions MJRefresh/MJRefreshConst.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define MJRefreshLabelFont [UIFont boldSystemFontOfSize:14]

// 常量
UIKIT_EXTERN const CGFloat MJRefreshLabelLeftInset;
UIKIT_EXTERN const CGFloat MJRefreshHeaderHeight;
UIKIT_EXTERN const CGFloat MJRefreshFooterHeight;
UIKIT_EXTERN const CGFloat MJRefreshFastAnimationDuration;
Expand Down
1 change: 1 addition & 0 deletions MJRefresh/MJRefreshConst.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000
#import <UIKit/UIKit.h>

const CGFloat MJRefreshLabelLeftInset = 25;
const CGFloat MJRefreshHeaderHeight = 54.0;
const CGFloat MJRefreshFooterHeight = 44.0;
const CGFloat MJRefreshFastAnimationDuration = 0.25;
Expand Down
31 changes: 12 additions & 19 deletions MJRefresh/NSBundle+MJRefresh.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,22 @@ + (NSString *)mj_localizedStringForKey:(NSString *)key value:(NSString *)value
{
static NSBundle *bundle = nil;
if (bundle == nil) {
// 获得设备的语言
// (iOS获取的语言字符串比较不稳定)目前框架只处理en、zh-Hans、zh-Hant三种情况,其他按照系统默认处理
NSString *language = [NSLocale preferredLanguages].firstObject;
// 如果是iOS9以上,去掉后面的设备购买地区比如zh-Hans-US和zh-Hans-CN后面的US和CN
if ([UIDevice currentDevice].systemVersion.floatValue >= 9.0) {
NSRange range = [language rangeOfString:@"-" options:NSBackwardsSearch];
if (range.location != NSNotFound) {
language = [language substringToIndex:range.location];
if ([language hasPrefix:@"en"]) {
language = @"en";
} else if ([language hasPrefix:@"zh"]) {
if ([language containsString:@"Hans"]) {
language = @"zh-Hans"; // 简体中文
} else { // zh-Hant\zh-HK\zh-TW
language = @"zh-Hant"; // 繁體中文
}
} else {
language = @"en";
}

if ([language isEqualToString:@"zh"]) { // zh-HK被去掉了-HK
language = @"zh-Hant";
}

if (language.length == 0) {
language = @"zh-Hans";
}

// 先从MJRefresh.bundle中查找资源
NSBundle *refreshBundle = [NSBundle mj_refreshBundle];
if ([refreshBundle.localizations containsObject:language]) {
bundle = [NSBundle bundleWithPath:[refreshBundle pathForResource:language ofType:@"lproj"]];
}
// 从MJRefresh.bundle中查找资源
bundle = [NSBundle bundleWithPath:[[NSBundle mj_refreshBundle] pathForResource:language ofType:@"lproj"]];
}
value = [bundle localizedStringForKey:key value:value table:nil];
return [[NSBundle mainBundle] localizedStringForKey:key value:value table:nil];
Expand Down
17 changes: 6 additions & 11 deletions MJRefreshExample/Base.lproj/LaunchScreen.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8191" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10116" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
Expand All @@ -11,34 +11,29 @@
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2015年 小码哥. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<rect key="frame" x="20" y="439" width="441" height="20.5"/>
<animations/>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2016年 小码哥. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<rect key="frame" x="20" y="439" width="441" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="MJRefresh" translatesAutoresizingMaskIntoConstraints="NO" id="XTX-D8-JkJ">
<rect key="frame" x="140" y="140" width="200" height="200"/>
<animations/>
<constraints>
<constraint firstAttribute="height" constant="200" id="Yjl-z0-AQq"/>
<constraint firstAttribute="width" constant="200" id="b2j-uN-0ek"/>
</constraints>
</imageView>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="http://www.520it.com" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="ofo-Sj-yNl">
<rect key="frame" x="20" y="398" width="440" height="20.5"/>
<animations/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="logo" translatesAutoresizingMaskIntoConstraints="NO" id="0ve-6E-pvp">
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Logo" translatesAutoresizingMaskIntoConstraints="NO" id="0ve-6E-pvp">
<rect key="frame" x="0.0" y="0.0" width="480" height="140"/>
<animations/>
</imageView>
</subviews>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="XTX-D8-JkJ" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="AF4-xX-WmS"/>
Expand All @@ -60,7 +55,7 @@
</view>
</objects>
<resources>
<image name="Logo" width="800" height="500"/>
<image name="MJRefresh" width="400" height="400"/>
<image name="logo" width="548" height="200"/>
</resources>
</document>
Loading

1 comment on commit 24008cf

@wangkeshuai
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

更新了3.1.12版本后下拉刷新不会驻留,直接回去了,而且页面会上移10个像素

Please sign in to comment.