Skip to content

Commit

Permalink
修复小问题
Browse files Browse the repository at this point in the history
1.本地化兼容pod 1.x和0.x的
2.箭头图片颜色跟随文字颜色
  • Loading branch information
MJ Lee authored and MJ Lee committed Jun 13, 2016
1 parent 51ff848 commit b28ed99
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 50 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.1'
s.version = '3.1.3'
s.summary = 'An easy way to use pull-to-refresh'
s.homepage = 'https://github.com/CoderMJLee/MJRefresh'
s.license = 'MIT'
Expand Down
7 changes: 6 additions & 1 deletion MJRefresh/Base/MJRefreshComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "MJRefreshConst.h"
#import "UIView+MJExtension.h"
#import "UIScrollView+MJRefresh.h"
#import "NSBundle+MJRefresh.h"

@interface MJRefreshComponent()
@property (strong, nonatomic) UIPanGestureRecognizer *pan;
Expand Down Expand Up @@ -149,8 +150,12 @@ - (NSString *)localizedStringForKey:(NSString *)key withDefault:(NSString *)defa
language = [language substringToIndex:range.location];
}

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

// 先从MJRefresh.bundle中查找资源
NSBundle *refreshBundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"MJRefresh" ofType:@"bundle"]];
NSBundle *refreshBundle = [NSBundle mj_refreshBundle];
if ([refreshBundle.localizations containsObject:language]) {
bundle = [NSBundle bundleWithPath:[refreshBundle pathForResource:language ofType:@"lproj"]];
}
Expand Down
6 changes: 4 additions & 2 deletions MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "MJRefreshBackNormalFooter.h"
#import "NSBundle+MJRefresh.h"

@interface MJRefreshBackNormalFooter()
{
Expand All @@ -20,8 +21,7 @@ @implementation MJRefreshBackNormalFooter
- (UIImageView *)arrowView
{
if (!_arrowView) {
UIImage *image = [UIImage imageNamed:MJRefreshSrcName(@"arrow.png")] ?: [UIImage imageNamed:MJRefreshFrameworkSrcName(@"arrow.png")];
UIImageView *arrowView = [[UIImageView alloc] initWithImage:image];
UIImageView *arrowView = [[UIImageView alloc] initWithImage:[NSBundle mj_arrowImage]];
[self addSubview:_arrowView = arrowView];
}
return _arrowView;
Expand Down Expand Up @@ -75,6 +75,8 @@ - (void)placeSubviews
if (self.loadingView.constraints.count == 0) {
self.loadingView.center = arrowCenter;
}

self.arrowView.tintColor = self.stateLabel.textColor;
}

- (void)setState:(MJRefreshState)state
Expand Down
7 changes: 4 additions & 3 deletions MJRefresh/Custom/Header/MJRefreshNormalHeader.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "MJRefreshNormalHeader.h"
#import "NSBundle+MJRefresh.h"

@interface MJRefreshNormalHeader()
{
Expand All @@ -20,9 +21,7 @@ @implementation MJRefreshNormalHeader
- (UIImageView *)arrowView
{
if (!_arrowView) {
UIImage *image = [UIImage imageNamed:MJRefreshSrcName(@"arrow.png")] ?: [UIImage imageNamed:MJRefreshFrameworkSrcName(@"arrow.png")];
UIImageView *arrowView = [[UIImageView alloc] initWithImage:[image imageWithRenderingMode:(UIImageRenderingModeAlwaysTemplate)]];
arrowView.tintColor = self.stateLabel.textColor;
UIImageView *arrowView = [[UIImageView alloc] initWithImage:[NSBundle mj_arrowImage]];
[self addSubview:_arrowView = arrowView];
}
return _arrowView;
Expand Down Expand Up @@ -84,6 +83,8 @@ - (void)placeSubviews
if (self.loadingView.constraints.count == 0) {
self.loadingView.center = arrowCenter;
}

self.arrowView.tintColor = self.stateLabel.textColor;
}

- (void)setState:(MJRefreshState)state
Expand Down
4 changes: 0 additions & 4 deletions MJRefresh/MJRefreshConst.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
// 字体大小
#define MJRefreshLabelFont [UIFont boldSystemFontOfSize:14]

// 图片路径
#define MJRefreshSrcName(file) [@"MJRefresh.bundle" stringByAppendingPathComponent:file]
#define MJRefreshFrameworkSrcName(file) [@"Frameworks/MJRefresh.framework/MJRefresh.bundle" stringByAppendingPathComponent:file]

// 常量
UIKIT_EXTERN const CGFloat MJRefreshHeaderHeight;
UIKIT_EXTERN const CGFloat MJRefreshFooterHeight;
Expand Down
14 changes: 14 additions & 0 deletions MJRefresh/NSBundle+MJRefresh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// NSBundle+MJRefresh.h
// MJRefreshExample
//
// Created by MJ Lee on 16/6/13.
// Copyright © 2016年 小码哥. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface NSBundle (MJRefresh)
+ (instancetype)mj_refreshBundle;
+ (UIImage *)mj_arrowImage;
@end
31 changes: 31 additions & 0 deletions MJRefresh/NSBundle+MJRefresh.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// NSBundle+MJRefresh.m
// MJRefreshExample
//
// Created by MJ Lee on 16/6/13.
// Copyright © 2016年 小码哥. All rights reserved.
//

#import "NSBundle+MJRefresh.h"
#import "MJRefreshComponent.h"

@implementation NSBundle (MJRefresh)
+ (instancetype)mj_refreshBundle
{
static NSBundle *refreshBundle = nil;
if (refreshBundle == nil) {
// 这里不使用mainBundle是为了适配pod 1.x和0.x
refreshBundle = [NSBundle bundleWithPath:[[NSBundle bundleForClass:[MJRefreshComponent class]] pathForResource:@"MJRefresh" ofType:@"bundle"]];
}
return refreshBundle;
}

+ (UIImage *)mj_arrowImage
{
static UIImage *arrowImage = nil;
if (arrowImage == nil) {
arrowImage = [[UIImage imageWithContentsOfFile:[[self mj_refreshBundle] pathForResource:@"arrow@2x" ofType:@"png"]] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
}
return arrowImage;
}
@end
Loading

0 comments on commit b28ed99

Please sign in to comment.