Skip to content

Commit

Permalink
添加控制展示样式
Browse files Browse the repository at this point in the history
  • Loading branch information
xhzengAIB committed Sep 1, 2014
1 parent e3d9c40 commit 91ee037
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@
*/
@property (nonatomic, assign) NSInteger requestCurrentPage;

/**
* 是否显示下拉刷新的标签文本,如果返回YES,按照正常排版,如果返回NO,那转圈居中,默认是YES
*/
@property (nonatomic, assign) BOOL hasStatusLabelShowed;

/**
* 圆圈的颜色,默认是[UIColor colorWithRed:173 / 255.0 green:53 / 255.0 blue:60 / 255.0 alpha:1]
*/
@property (nonatomic, strong) UIColor *circleColor;

/**
* 圆圈的线条粗细,默认为1, 最大为2
*/
@property (nonatomic, assign) CGFloat circleLineWidth;

/**
* 自动下拉刷新调用的方法,必须放在viewDidAppear方法内,别把这行代码放到别处,然后导致了错误,那就不好了嘛!
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ - (BOOL)isLoadingDataSource {
- (void)setupRefreshControl {
if (!_refreshControl) {
_refreshControl = [[XHRefreshControl alloc] initWithScrollView:self.tableView delegate:self];
_refreshControl.hasStatusLabelShowed = self.hasStatusLabelShowed;
_refreshControl.circleColor = self.circleColor;
_refreshControl.circleLineWidth = self.circleLineWidth;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@
*/
@property (nonatomic, assign) NSInteger requestCurrentPage;

/**
* 是否显示下拉刷新的标签文本,如果返回YES,按照正常排版,如果返回NO,那转圈居中,默认是YES
*/
@property (nonatomic, assign) BOOL hasStatusLabelShowed;

/**
* 圆圈的颜色,默认是[UIColor colorWithRed:173 / 255.0 green:53 / 255.0 blue:60 / 255.0 alpha:1]
*/
@property (nonatomic, strong) UIColor *circleColor;

/**
* 圆圈的线条粗细,默认为1, 最大为2
*/
@property (nonatomic, assign) CGFloat circleLineWidth;

/**
* 自动下拉刷新调用的方法,必须放在viewDidAppear方法内,别把这行代码放到别处,然后导致了错误,那就不好了嘛!
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ - (BOOL)isLoadingDataSource {
- (void)setupRefreshControl {
if (!_customRefreshControl) {
_customRefreshControl = [[XHRefreshControl alloc] initWithScrollView:self.tableView delegate:self];
_customRefreshControl.hasStatusLabelShowed = self.hasStatusLabelShowed;
_customRefreshControl.circleColor = self.circleColor;
_customRefreshControl.circleLineWidth = self.circleLineWidth;
}
}

Expand Down
17 changes: 16 additions & 1 deletion RefreshControl/Manager/XHRefreshControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,26 @@
*/
- (NSString *)displayAutoLoadMoreRefreshedMessage;


@end

@interface XHRefreshControl : NSObject

/**
* 是否显示下拉刷新的标签文本,如果返回YES,按照正常排版,如果返回NO,那转圈居中,默认是YES
*/
@property (nonatomic, assign) BOOL hasStatusLabelShowed;

/**
* 圆圈的颜色,默认是[UIColor colorWithRed:173 / 255.0 green:53 / 255.0 blue:60 / 255.0 alpha:1]
*/
@property (nonatomic, strong) UIColor *circleColor;

/**
* 圆圈的线条粗细,默认为1, 最大为2
*/
@property (nonatomic, assign) CGFloat circleLineWidth;


- (id)initWithScrollView:(UIScrollView *)scrollView delegate:(id <XHRefreshControlDelegate>)delegate;

/**
Expand Down
21 changes: 21 additions & 0 deletions RefreshControl/Manager/XHRefreshControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,21 @@ - (XHLoadMoreView *)loadMoreView {
return _loadMoreView;
}

- (void)setHasStatusLabelShowed:(BOOL)hasStatusLabelShowed {
_hasStatusLabelShowed = hasStatusLabelShowed;
self.refreshCircleContainerView.hasStatusLabelShowed = hasStatusLabelShowed;
}

- (void)setCircleColor:(UIColor *)circleColor {
_circleColor = circleColor;
self.refreshCircleContainerView.circleView.circleColor = circleColor;
}

- (void)setCircleLineWidth:(CGFloat)circleLineWidth {
_circleLineWidth = circleLineWidth;
self.refreshCircleContainerView.circleView.circleLineWidth = circleLineWidth;
}

#pragma mark - Getter Method

- (BOOL)isPullDownRefreshed {
Expand Down Expand Up @@ -498,6 +513,12 @@ - (void)setup {
if (self.isLoadMoreRefreshed) {
[self.scrollView addSubview:self.loadMoreView];
}

self.hasStatusLabelShowed = YES;

self.circleColor = [UIColor colorWithRed:173 / 255.0 green:53 / 255.0 blue:60 / 255.0 alpha:1];

self.circleLineWidth = 1.0;
}

- (id)initWithScrollView:(UIScrollView *)scrollView delegate:(id <XHRefreshControlDelegate>)delegate {
Expand Down
10 changes: 10 additions & 0 deletions RefreshControl/Views/XHCircleView.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
*/
@property (nonatomic, assign) XHRefreshViewLayerType refreshViewLayerType;

/**
* 圆圈的颜色,默认是[UIColor colorWithRed:173 / 255.0 green:53 / 255.0 blue:60 / 255.0 alpha:1]
*/
@property (nonatomic, strong) UIColor *circleColor;

/**
* 圆圈的线条粗细
*/
@property (nonatomic, assign) CGFloat circleLineWidth;

/**
* 旋转的animation
*
Expand Down
4 changes: 2 additions & 2 deletions RefreshControl/Views/XHCircleView.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ - (void)drawRect:(CGRect)rect {

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:173 / 255.0 green:53 / 255.0 blue:60 / 255.0 alpha:1].CGColor);
CGContextSetLineWidth(context, 1.f);
CGContextSetStrokeColorWithColor(context, self.circleColor.CGColor);
CGContextSetLineWidth(context, self.circleLineWidth);

static CGFloat radius = 9;
if (self.refreshViewLayerType) {
Expand Down
5 changes: 5 additions & 0 deletions RefreshControl/Views/XHRefreshCircleContainerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@
*/
@property (nonatomic, strong) UILabel *timeLabel;

/**
* 是否显示下拉刷新的标签文本,如果返回YES,按照正常排版,如果返回NO,那转圈居中
*/
@property (nonatomic, assign) BOOL hasStatusLabelShowed;

@end
12 changes: 12 additions & 0 deletions RefreshControl/Views/XHRefreshCircleContainerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ @implementation XHRefreshCircleContainerView

#pragma mark - Propertys

- (void)setHasStatusLabelShowed:(BOOL)hasStatusLabelShowed {
_hasStatusLabelShowed = hasStatusLabelShowed;

if (hasStatusLabelShowed) {
self.circleView.frame = CGRectMake((CGRectGetWidth(self.bounds) - kXHRefreshCircleViewHeight) / 2 - 40, (CGRectGetHeight(self.bounds) - kXHRefreshCircleViewHeight) / 2 - 5, kXHRefreshCircleViewHeight, kXHRefreshCircleViewHeight);
} else {
self.circleView.center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
}
self.stateLabel.hidden = !hasStatusLabelShowed;
self.timeLabel.hidden = !hasStatusLabelShowed;
}

- (XHCircleView *)circleView {
if (!_circleView) {
_circleView = [[XHCircleView alloc] initWithFrame:CGRectMake((CGRectGetWidth(self.bounds) - kXHRefreshCircleViewHeight) / 2 - 40, (CGRectGetHeight(self.bounds) - kXHRefreshCircleViewHeight) / 2 - 5, kXHRefreshCircleViewHeight, kXHRefreshCircleViewHeight)];
Expand Down

0 comments on commit 91ee037

Please sign in to comment.