├── CustomTableVc.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── Charles.xcuserdatad │ └── xcschemes │ ├── CustomTableVc.xcscheme │ └── xcschememanagement.plist ├── CustomTableVc ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Charles │ ├── MJRefresh │ │ ├── LICENSE │ │ ├── MJRefresh │ │ │ ├── Base │ │ │ │ ├── MJRefreshAutoFooter.h │ │ │ │ ├── MJRefreshAutoFooter.m │ │ │ │ ├── MJRefreshBackFooter.h │ │ │ │ ├── MJRefreshBackFooter.m │ │ │ │ ├── MJRefreshComponent.h │ │ │ │ ├── MJRefreshComponent.m │ │ │ │ ├── MJRefreshFooter.h │ │ │ │ ├── MJRefreshFooter.m │ │ │ │ ├── MJRefreshHeader.h │ │ │ │ └── MJRefreshHeader.m │ │ │ ├── Custom │ │ │ │ ├── Footer │ │ │ │ │ ├── Auto │ │ │ │ │ │ ├── MJRefreshAutoGifFooter.h │ │ │ │ │ │ ├── MJRefreshAutoGifFooter.m │ │ │ │ │ │ ├── MJRefreshAutoNormalFooter.h │ │ │ │ │ │ ├── MJRefreshAutoNormalFooter.m │ │ │ │ │ │ ├── MJRefreshAutoStateFooter.h │ │ │ │ │ │ └── MJRefreshAutoStateFooter.m │ │ │ │ │ └── Back │ │ │ │ │ │ ├── MJRefreshBackGifFooter.h │ │ │ │ │ │ ├── MJRefreshBackGifFooter.m │ │ │ │ │ │ ├── MJRefreshBackNormalFooter.h │ │ │ │ │ │ ├── MJRefreshBackNormalFooter.m │ │ │ │ │ │ ├── MJRefreshBackStateFooter.h │ │ │ │ │ │ └── MJRefreshBackStateFooter.m │ │ │ │ └── Header │ │ │ │ │ ├── MJRefreshGifHeader.h │ │ │ │ │ ├── MJRefreshGifHeader.m │ │ │ │ │ ├── MJRefreshNormalHeader.h │ │ │ │ │ ├── MJRefreshNormalHeader.m │ │ │ │ │ ├── MJRefreshStateHeader.h │ │ │ │ │ └── MJRefreshStateHeader.m │ │ │ ├── MJRefresh.bundle │ │ │ │ ├── arrow@2x.png │ │ │ │ ├── en.lproj │ │ │ │ │ └── Localizable.strings │ │ │ │ ├── zh-Hans.lproj │ │ │ │ │ └── Localizable.strings │ │ │ │ └── zh-Hant.lproj │ │ │ │ │ └── Localizable.strings │ │ │ ├── MJRefresh.h │ │ │ ├── MJRefreshConst.h │ │ │ ├── MJRefreshConst.m │ │ │ ├── NSBundle+MJRefresh.h │ │ │ ├── NSBundle+MJRefresh.m │ │ │ ├── UIScrollView+MJExtension.h │ │ │ ├── UIScrollView+MJExtension.m │ │ │ ├── UIScrollView+MJRefresh.h │ │ │ ├── UIScrollView+MJRefresh.m │ │ │ ├── UIView+MJExtension.h │ │ │ └── UIView+MJExtension.m │ │ └── README.md │ ├── Masonry │ │ ├── LICENSE │ │ ├── Masonry │ │ │ ├── MASCompositeConstraint.h │ │ │ ├── MASCompositeConstraint.m │ │ │ ├── MASConstraint+Private.h │ │ │ ├── MASConstraint.h │ │ │ ├── MASConstraint.m │ │ │ ├── MASConstraintMaker.h │ │ │ ├── MASConstraintMaker.m │ │ │ ├── MASLayoutConstraint.h │ │ │ ├── MASLayoutConstraint.m │ │ │ ├── MASUtilities.h │ │ │ ├── MASViewAttribute.h │ │ │ ├── MASViewAttribute.m │ │ │ ├── MASViewConstraint.h │ │ │ ├── MASViewConstraint.m │ │ │ ├── Masonry.h │ │ │ ├── NSArray+MASAdditions.h │ │ │ ├── NSArray+MASAdditions.m │ │ │ ├── NSArray+MASShorthandAdditions.h │ │ │ ├── NSLayoutConstraint+MASDebugAdditions.h │ │ │ ├── NSLayoutConstraint+MASDebugAdditions.m │ │ │ ├── View+MASAdditions.h │ │ │ ├── View+MASAdditions.m │ │ │ └── View+MASShorthandAdditions.h │ │ └── README.md │ ├── UIView+Frame.h │ ├── UIView+Frame.m │ ├── UIView+XRNib.h │ ├── UIView+XRNib.m │ ├── UIView+XRTap.h │ ├── UIView+XRTap.m │ ├── XRBaseTableHeaderFooterView.h │ ├── XRBaseTableHeaderFooterView.m │ ├── XRBaseTableView.h │ ├── XRBaseTableView.m │ ├── XRBaseTableViewCell.h │ ├── XRBaseTableViewCell.m │ ├── XRBaseTableViewController.h │ ├── XRBaseTableViewController.m │ ├── XRSlideOperationViewCell.h │ ├── XRSlideOperationViewCell.m │ ├── XRUtils.h │ └── XRUtils.m ├── Demo1ViewController.h ├── Demo1ViewController.m ├── Info.plist ├── ViewController.h ├── ViewController.m ├── XRSlideTestCell.h ├── XRSlideTestCell.m └── main.m ├── CustomTableVcTests ├── CustomTableVcTests.m └── Info.plist ├── CustomTableVcUITests ├── CustomTableVcUITests.m └── Info.plist └── README.md /CustomTableVc.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CustomTableVc.xcodeproj/xcuserdata/Charles.xcuserdatad/xcschemes/CustomTableVc.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /CustomTableVc.xcodeproj/xcuserdata/Charles.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | CustomTableVc.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 569E5F4D1D40E4D3000D8B80 16 | 17 | primary 18 | 19 | 20 | 569E5F661D40E4D4000D8B80 21 | 22 | primary 23 | 24 | 25 | 569E5F711D40E4D4000D8B80 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /CustomTableVc/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // CustomTableVc 4 | // 5 | // Created by Charles on 16/7/21. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /CustomTableVc/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // CustomTableVc 4 | // 5 | // Created by Charles on 16/7/21. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /CustomTableVc/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /CustomTableVc/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /CustomTableVc/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 MJRefresh (https://github.com/CoderMJLee/MJRefresh) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Base/MJRefreshAutoFooter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshAutoFooter.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshFooter.h" 10 | 11 | @interface MJRefreshAutoFooter : MJRefreshFooter 12 | /** 是否自动刷新(默认为YES) */ 13 | @property (assign, nonatomic, getter=isAutomaticallyRefresh) BOOL automaticallyRefresh; 14 | 15 | /** 当底部控件出现多少时就自动刷新(默认为1.0,也就是底部控件完全出现时,才会自动刷新) */ 16 | @property (assign, nonatomic) CGFloat appearencePercentTriggerAutoRefresh MJRefreshDeprecated("请使用automaticallyChangeAlpha属性"); 17 | 18 | /** 当底部控件出现多少时就自动刷新(默认为1.0,也就是底部控件完全出现时,才会自动刷新) */ 19 | @property (assign, nonatomic) CGFloat triggerAutomaticallyRefreshPercent; 20 | @end 21 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Base/MJRefreshAutoFooter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshAutoFooter.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshAutoFooter.h" 10 | 11 | @interface MJRefreshAutoFooter() 12 | @end 13 | 14 | @implementation MJRefreshAutoFooter 15 | 16 | #pragma mark - 初始化 17 | - (void)willMoveToSuperview:(UIView *)newSuperview 18 | { 19 | [super willMoveToSuperview:newSuperview]; 20 | 21 | if (newSuperview) { // 新的父控件 22 | if (self.hidden == NO) { 23 | self.scrollView.mj_insetB += self.mj_h; 24 | } 25 | 26 | // 设置位置 27 | self.mj_y = _scrollView.mj_contentH; 28 | } else { // 被移除了 29 | if (self.hidden == NO) { 30 | self.scrollView.mj_insetB -= self.mj_h; 31 | } 32 | } 33 | } 34 | 35 | #pragma mark - 过期方法 36 | - (void)setAppearencePercentTriggerAutoRefresh:(CGFloat)appearencePercentTriggerAutoRefresh 37 | { 38 | self.triggerAutomaticallyRefreshPercent = appearencePercentTriggerAutoRefresh; 39 | } 40 | 41 | - (CGFloat)appearencePercentTriggerAutoRefresh 42 | { 43 | return self.triggerAutomaticallyRefreshPercent; 44 | } 45 | 46 | #pragma mark - 实现父类的方法 47 | - (void)prepare 48 | { 49 | [super prepare]; 50 | 51 | // 默认底部控件100%出现时才会自动刷新 52 | self.triggerAutomaticallyRefreshPercent = 1.0; 53 | 54 | // 设置为默认状态 55 | self.automaticallyRefresh = YES; 56 | } 57 | 58 | - (void)scrollViewContentSizeDidChange:(NSDictionary *)change 59 | { 60 | [super scrollViewContentSizeDidChange:change]; 61 | 62 | // 设置位置 63 | self.mj_y = self.scrollView.mj_contentH; 64 | } 65 | 66 | - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change 67 | { 68 | [super scrollViewContentOffsetDidChange:change]; 69 | 70 | if (self.state != MJRefreshStateIdle || !self.automaticallyRefresh || self.mj_y == 0) return; 71 | 72 | if (_scrollView.mj_insetT + _scrollView.mj_contentH > _scrollView.mj_h) { // 内容超过一个屏幕 73 | // 这里的_scrollView.mj_contentH替换掉self.mj_y更为合理 74 | if (_scrollView.mj_offsetY >= _scrollView.mj_contentH - _scrollView.mj_h + self.mj_h * self.triggerAutomaticallyRefreshPercent + _scrollView.mj_insetB - self.mj_h) { 75 | // 防止手松开时连续调用 76 | CGPoint old = [change[@"old"] CGPointValue]; 77 | CGPoint new = [change[@"new"] CGPointValue]; 78 | if (new.y <= old.y) return; 79 | 80 | // 当底部刷新控件完全出现时,才刷新 81 | [self beginRefreshing]; 82 | } 83 | } 84 | } 85 | 86 | - (void)scrollViewPanStateDidChange:(NSDictionary *)change 87 | { 88 | [super scrollViewPanStateDidChange:change]; 89 | 90 | if (self.state != MJRefreshStateIdle) return; 91 | 92 | if (_scrollView.panGestureRecognizer.state == UIGestureRecognizerStateEnded) {// 手松开 93 | if (_scrollView.mj_insetT + _scrollView.mj_contentH <= _scrollView.mj_h) { // 不够一个屏幕 94 | if (_scrollView.mj_offsetY >= - _scrollView.mj_insetT) { // 向上拽 95 | [self beginRefreshing]; 96 | } 97 | } else { // 超出一个屏幕 98 | if (_scrollView.mj_offsetY >= _scrollView.mj_contentH + _scrollView.mj_insetB - _scrollView.mj_h) { 99 | [self beginRefreshing]; 100 | } 101 | } 102 | } 103 | } 104 | 105 | - (void)setState:(MJRefreshState)state 106 | { 107 | MJRefreshCheckState 108 | 109 | if (state == MJRefreshStateRefreshing) { 110 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 111 | [self executeRefreshingCallback]; 112 | }); 113 | } else if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) { 114 | if (MJRefreshStateRefreshing == oldState) { 115 | if (self.endRefreshingCompletionBlock) { 116 | self.endRefreshingCompletionBlock(); 117 | } 118 | } 119 | } 120 | } 121 | 122 | - (void)setHidden:(BOOL)hidden 123 | { 124 | BOOL lastHidden = self.isHidden; 125 | 126 | [super setHidden:hidden]; 127 | 128 | if (!lastHidden && hidden) { 129 | self.state = MJRefreshStateIdle; 130 | 131 | self.scrollView.mj_insetB -= self.mj_h; 132 | } else if (lastHidden && !hidden) { 133 | self.scrollView.mj_insetB += self.mj_h; 134 | 135 | // 设置位置 136 | self.mj_y = _scrollView.mj_contentH; 137 | } 138 | } 139 | @end 140 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Base/MJRefreshBackFooter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshBackFooter.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshFooter.h" 10 | 11 | @interface MJRefreshBackFooter : MJRefreshFooter 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Base/MJRefreshBackFooter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshBackFooter.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshBackFooter.h" 10 | 11 | @interface MJRefreshBackFooter() 12 | @property (assign, nonatomic) NSInteger lastRefreshCount; 13 | @property (assign, nonatomic) CGFloat lastBottomDelta; 14 | @end 15 | 16 | @implementation MJRefreshBackFooter 17 | 18 | #pragma mark - 初始化 19 | - (void)willMoveToSuperview:(UIView *)newSuperview 20 | { 21 | [super willMoveToSuperview:newSuperview]; 22 | 23 | [self scrollViewContentSizeDidChange:nil]; 24 | } 25 | 26 | #pragma mark - 实现父类的方法 27 | - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change 28 | { 29 | [super scrollViewContentOffsetDidChange:change]; 30 | 31 | // 如果正在刷新,直接返回 32 | if (self.state == MJRefreshStateRefreshing) return; 33 | 34 | _scrollViewOriginalInset = self.scrollView.contentInset; 35 | 36 | // 当前的contentOffset 37 | CGFloat currentOffsetY = self.scrollView.mj_offsetY; 38 | // 尾部控件刚好出现的offsetY 39 | CGFloat happenOffsetY = [self happenOffsetY]; 40 | // 如果是向下滚动到看不见尾部控件,直接返回 41 | if (currentOffsetY <= happenOffsetY) return; 42 | 43 | CGFloat pullingPercent = (currentOffsetY - happenOffsetY) / self.mj_h; 44 | 45 | // 如果已全部加载,仅设置pullingPercent,然后返回 46 | if (self.state == MJRefreshStateNoMoreData) { 47 | self.pullingPercent = pullingPercent; 48 | return; 49 | } 50 | 51 | if (self.scrollView.isDragging) { 52 | self.pullingPercent = pullingPercent; 53 | // 普通 和 即将刷新 的临界点 54 | CGFloat normal2pullingOffsetY = happenOffsetY + self.mj_h; 55 | 56 | if (self.state == MJRefreshStateIdle && currentOffsetY > normal2pullingOffsetY) { 57 | // 转为即将刷新状态 58 | self.state = MJRefreshStatePulling; 59 | } else if (self.state == MJRefreshStatePulling && currentOffsetY <= normal2pullingOffsetY) { 60 | // 转为普通状态 61 | self.state = MJRefreshStateIdle; 62 | } 63 | } else if (self.state == MJRefreshStatePulling) {// 即将刷新 && 手松开 64 | // 开始刷新 65 | [self beginRefreshing]; 66 | } else if (pullingPercent < 1) { 67 | self.pullingPercent = pullingPercent; 68 | } 69 | } 70 | 71 | - (void)scrollViewContentSizeDidChange:(NSDictionary *)change 72 | { 73 | [super scrollViewContentSizeDidChange:change]; 74 | 75 | // 内容的高度 76 | CGFloat contentHeight = self.scrollView.mj_contentH + self.ignoredScrollViewContentInsetBottom; 77 | // 表格的高度 78 | CGFloat scrollHeight = self.scrollView.mj_h - self.scrollViewOriginalInset.top - self.scrollViewOriginalInset.bottom + self.ignoredScrollViewContentInsetBottom; 79 | // 设置位置和尺寸 80 | self.mj_y = MAX(contentHeight, scrollHeight); 81 | } 82 | 83 | - (void)setState:(MJRefreshState)state 84 | { 85 | MJRefreshCheckState 86 | 87 | // 根据状态来设置属性 88 | if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) { 89 | // 刷新完毕 90 | if (MJRefreshStateRefreshing == oldState) { 91 | [UIView animateWithDuration:MJRefreshSlowAnimationDuration animations:^{ 92 | self.scrollView.mj_insetB -= self.lastBottomDelta; 93 | 94 | // 自动调整透明度 95 | if (self.isAutomaticallyChangeAlpha) self.alpha = 0.0; 96 | } completion:^(BOOL finished) { 97 | self.pullingPercent = 0.0; 98 | 99 | if (self.endRefreshingCompletionBlock) { 100 | self.endRefreshingCompletionBlock(); 101 | } 102 | }]; 103 | } 104 | 105 | CGFloat deltaH = [self heightForContentBreakView]; 106 | // 刚刷新完毕 107 | if (MJRefreshStateRefreshing == oldState && deltaH > 0 && self.scrollView.mj_totalDataCount != self.lastRefreshCount) { 108 | self.scrollView.mj_offsetY = self.scrollView.mj_offsetY; 109 | } 110 | } else if (state == MJRefreshStateRefreshing) { 111 | // 记录刷新前的数量 112 | self.lastRefreshCount = self.scrollView.mj_totalDataCount; 113 | 114 | [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ 115 | CGFloat bottom = self.mj_h + self.scrollViewOriginalInset.bottom; 116 | CGFloat deltaH = [self heightForContentBreakView]; 117 | if (deltaH < 0) { // 如果内容高度小于view的高度 118 | bottom -= deltaH; 119 | } 120 | self.lastBottomDelta = bottom - self.scrollView.mj_insetB; 121 | self.scrollView.mj_insetB = bottom; 122 | self.scrollView.mj_offsetY = [self happenOffsetY] + self.mj_h; 123 | } completion:^(BOOL finished) { 124 | [self executeRefreshingCallback]; 125 | }]; 126 | } 127 | } 128 | 129 | - (void)endRefreshing 130 | { 131 | dispatch_async(dispatch_get_main_queue(), ^{ 132 | self.state = MJRefreshStateIdle; 133 | }); 134 | } 135 | 136 | - (void)endRefreshingWithNoMoreData 137 | { 138 | dispatch_async(dispatch_get_main_queue(), ^{ 139 | self.state = MJRefreshStateNoMoreData; 140 | }); 141 | } 142 | #pragma mark - 私有方法 143 | #pragma mark 获得scrollView的内容 超出 view 的高度 144 | - (CGFloat)heightForContentBreakView 145 | { 146 | CGFloat h = self.scrollView.frame.size.height - self.scrollViewOriginalInset.bottom - self.scrollViewOriginalInset.top; 147 | return self.scrollView.contentSize.height - h; 148 | } 149 | 150 | #pragma mark 刚好看到上拉刷新控件时的contentOffset.y 151 | - (CGFloat)happenOffsetY 152 | { 153 | CGFloat deltaH = [self heightForContentBreakView]; 154 | if (deltaH > 0) { 155 | return deltaH - self.scrollViewOriginalInset.top; 156 | } else { 157 | return - self.scrollViewOriginalInset.top; 158 | } 159 | } 160 | @end 161 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Base/MJRefreshComponent.h: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: 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 3 | // MJRefreshComponent.h 4 | // MJRefreshExample 5 | // 6 | // Created by MJ Lee on 15/3/4. 7 | // Copyright (c) 2015年 小码哥. All rights reserved. 8 | // 刷新控件的基类 9 | 10 | #import 11 | #import "MJRefreshConst.h" 12 | #import "UIView+MJExtension.h" 13 | #import "UIScrollView+MJExtension.h" 14 | #import "UIScrollView+MJRefresh.h" 15 | #import "NSBundle+MJRefresh.h" 16 | 17 | /** 刷新控件的状态 */ 18 | typedef NS_ENUM(NSInteger, MJRefreshState) { 19 | /** 普通闲置状态 */ 20 | MJRefreshStateIdle = 1, 21 | /** 松开就可以进行刷新的状态 */ 22 | MJRefreshStatePulling, 23 | /** 正在刷新中的状态 */ 24 | MJRefreshStateRefreshing, 25 | /** 即将刷新的状态 */ 26 | MJRefreshStateWillRefresh, 27 | /** 所有数据加载完毕,没有更多的数据了 */ 28 | MJRefreshStateNoMoreData 29 | }; 30 | 31 | /** 进入刷新状态的回调 */ 32 | typedef void (^MJRefreshComponentRefreshingBlock)(); 33 | /** 开始刷新后的回调(进入刷新状态后的回调) */ 34 | typedef void (^MJRefreshComponentbeginRefreshingCompletionBlock)(); 35 | /** 结束刷新后的回调 */ 36 | typedef void (^MJRefreshComponentEndRefreshingCompletionBlock)(); 37 | 38 | /** 刷新控件的基类 */ 39 | @interface MJRefreshComponent : UIView 40 | { 41 | /** 记录scrollView刚开始的inset */ 42 | UIEdgeInsets _scrollViewOriginalInset; 43 | /** 父控件 */ 44 | __weak UIScrollView *_scrollView; 45 | } 46 | #pragma mark - 刷新回调 47 | /** 正在刷新的回调 */ 48 | @property (copy, nonatomic) MJRefreshComponentRefreshingBlock refreshingBlock; 49 | /** 设置回调对象和回调方法 */ 50 | - (void)setRefreshingTarget:(id)target refreshingAction:(SEL)action; 51 | 52 | /** 回调对象 */ 53 | @property (weak, nonatomic) id refreshingTarget; 54 | /** 回调方法 */ 55 | @property (assign, nonatomic) SEL refreshingAction; 56 | /** 触发回调(交给子类去调用) */ 57 | - (void)executeRefreshingCallback; 58 | 59 | #pragma mark - 刷新状态控制 60 | /** 进入刷新状态 */ 61 | - (void)beginRefreshing; 62 | - (void)beginRefreshingWithCompletionBlock:(void (^)())completionBlock; 63 | /** 开始刷新后的回调(进入刷新状态后的回调) */ 64 | @property (copy, nonatomic) MJRefreshComponentbeginRefreshingCompletionBlock beginRefreshingCompletionBlock; 65 | /** 结束刷新的回调 */ 66 | @property (copy, nonatomic) MJRefreshComponentEndRefreshingCompletionBlock endRefreshingCompletionBlock; 67 | /** 结束刷新状态 */ 68 | - (void)endRefreshing; 69 | - (void)endRefreshingWithCompletionBlock:(void (^)())completionBlock; 70 | /** 是否正在刷新 */ 71 | - (BOOL)isRefreshing; 72 | /** 刷新状态 一般交给子类内部实现 */ 73 | @property (assign, nonatomic) MJRefreshState state; 74 | 75 | #pragma mark - 交给子类去访问 76 | /** 记录scrollView刚开始的inset */ 77 | @property (assign, nonatomic, readonly) UIEdgeInsets scrollViewOriginalInset; 78 | /** 父控件 */ 79 | @property (weak, nonatomic, readonly) UIScrollView *scrollView; 80 | 81 | #pragma mark - 交给子类们去实现 82 | /** 初始化 */ 83 | - (void)prepare NS_REQUIRES_SUPER; 84 | /** 摆放子控件frame */ 85 | - (void)placeSubviews NS_REQUIRES_SUPER; 86 | /** 当scrollView的contentOffset发生改变的时候调用 */ 87 | - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change NS_REQUIRES_SUPER; 88 | /** 当scrollView的contentSize发生改变的时候调用 */ 89 | - (void)scrollViewContentSizeDidChange:(NSDictionary *)change NS_REQUIRES_SUPER; 90 | /** 当scrollView的拖拽状态发生改变的时候调用 */ 91 | - (void)scrollViewPanStateDidChange:(NSDictionary *)change NS_REQUIRES_SUPER; 92 | 93 | 94 | #pragma mark - 其他 95 | /** 拉拽的百分比(交给子类重写) */ 96 | @property (assign, nonatomic) CGFloat pullingPercent; 97 | /** 根据拖拽比例自动切换透明度 */ 98 | @property (assign, nonatomic, getter=isAutoChangeAlpha) BOOL autoChangeAlpha MJRefreshDeprecated("请使用automaticallyChangeAlpha属性"); 99 | /** 根据拖拽比例自动切换透明度 */ 100 | @property (assign, nonatomic, getter=isAutomaticallyChangeAlpha) BOOL automaticallyChangeAlpha; 101 | @end 102 | 103 | @interface UILabel(MJRefresh) 104 | + (instancetype)mj_label; 105 | - (CGFloat)mj_textWith; 106 | @end 107 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Base/MJRefreshFooter.h: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: 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 3 | // MJRefreshFooter.h 4 | // MJRefreshExample 5 | // 6 | // Created by MJ Lee on 15/3/5. 7 | // Copyright (c) 2015年 小码哥. All rights reserved. 8 | // 上拉刷新控件 9 | 10 | #import "MJRefreshComponent.h" 11 | 12 | @interface MJRefreshFooter : MJRefreshComponent 13 | /** 创建footer */ 14 | + (instancetype)footerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock; 15 | /** 创建footer */ 16 | + (instancetype)footerWithRefreshingTarget:(id)target refreshingAction:(SEL)action; 17 | 18 | /** 提示没有更多的数据 */ 19 | - (void)endRefreshingWithNoMoreData; 20 | - (void)noticeNoMoreData MJRefreshDeprecated("使用endRefreshingWithNoMoreData"); 21 | 22 | /** 重置没有更多的数据(消除没有更多数据的状态) */ 23 | - (void)resetNoMoreData; 24 | 25 | /** 忽略多少scrollView的contentInset的bottom */ 26 | @property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetBottom; 27 | 28 | /** 自动根据有无数据来显示和隐藏(有数据就显示,没有数据隐藏。默认是NO) */ 29 | @property (assign, nonatomic, getter=isAutomaticallyHidden) BOOL automaticallyHidden; 30 | @end 31 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Base/MJRefreshFooter.m: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: 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 3 | // MJRefreshFooter.m 4 | // MJRefreshExample 5 | // 6 | // Created by MJ Lee on 15/3/5. 7 | // Copyright (c) 2015年 小码哥. All rights reserved. 8 | // 9 | 10 | #import "MJRefreshFooter.h" 11 | 12 | @interface MJRefreshFooter() 13 | 14 | @end 15 | 16 | @implementation MJRefreshFooter 17 | #pragma mark - 构造方法 18 | + (instancetype)footerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock 19 | { 20 | MJRefreshFooter *cmp = [[self alloc] init]; 21 | cmp.refreshingBlock = refreshingBlock; 22 | return cmp; 23 | } 24 | + (instancetype)footerWithRefreshingTarget:(id)target refreshingAction:(SEL)action 25 | { 26 | MJRefreshFooter *cmp = [[self alloc] init]; 27 | [cmp setRefreshingTarget:target refreshingAction:action]; 28 | return cmp; 29 | } 30 | 31 | #pragma mark - 重写父类的方法 32 | - (void)prepare 33 | { 34 | [super prepare]; 35 | 36 | // 设置自己的高度 37 | self.mj_h = MJRefreshFooterHeight; 38 | 39 | // 默认不会自动隐藏 40 | self.automaticallyHidden = NO; 41 | } 42 | 43 | - (void)willMoveToSuperview:(UIView *)newSuperview 44 | { 45 | [super willMoveToSuperview:newSuperview]; 46 | 47 | if (newSuperview) { 48 | // 监听scrollView数据的变化 49 | if ([self.scrollView isKindOfClass:[UITableView class]] || [self.scrollView isKindOfClass:[UICollectionView class]]) { 50 | [self.scrollView setMj_reloadDataBlock:^(NSInteger totalDataCount) { 51 | if (self.isAutomaticallyHidden) { 52 | self.hidden = (totalDataCount == 0); 53 | } 54 | }]; 55 | } 56 | } 57 | } 58 | 59 | #pragma mark - 公共方法 60 | - (void)endRefreshingWithNoMoreData 61 | { 62 | self.state = MJRefreshStateNoMoreData; 63 | } 64 | 65 | - (void)noticeNoMoreData 66 | { 67 | [self endRefreshingWithNoMoreData]; 68 | } 69 | 70 | - (void)resetNoMoreData 71 | { 72 | self.state = MJRefreshStateIdle; 73 | } 74 | @end 75 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Base/MJRefreshHeader.h: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: 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 3 | // MJRefreshHeader.h 4 | // MJRefreshExample 5 | // 6 | // Created by MJ Lee on 15/3/4. 7 | // Copyright (c) 2015年 小码哥. All rights reserved. 8 | // 下拉刷新控件:负责监控用户下拉的状态 9 | 10 | #import "MJRefreshComponent.h" 11 | 12 | @interface MJRefreshHeader : MJRefreshComponent 13 | /** 创建header */ 14 | + (instancetype)headerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock; 15 | /** 创建header */ 16 | + (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action; 17 | 18 | /** 这个key用来存储上一次下拉刷新成功的时间 */ 19 | @property (copy, nonatomic) NSString *lastUpdatedTimeKey; 20 | /** 上一次下拉刷新成功的时间 */ 21 | @property (strong, nonatomic, readonly) NSDate *lastUpdatedTime; 22 | 23 | /** 忽略多少scrollView的contentInset的top */ 24 | @property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetTop; 25 | @end 26 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Base/MJRefreshHeader.m: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: 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 3 | // MJRefreshHeader.m 4 | // MJRefreshExample 5 | // 6 | // Created by MJ Lee on 15/3/4. 7 | // Copyright (c) 2015年 小码哥. All rights reserved. 8 | // 9 | 10 | #import "MJRefreshHeader.h" 11 | 12 | @interface MJRefreshHeader() 13 | @property (assign, nonatomic) CGFloat insetTDelta; 14 | @end 15 | 16 | @implementation MJRefreshHeader 17 | #pragma mark - 构造方法 18 | + (instancetype)headerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock 19 | { 20 | MJRefreshHeader *cmp = [[self alloc] init]; 21 | cmp.refreshingBlock = refreshingBlock; 22 | return cmp; 23 | } 24 | + (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action 25 | { 26 | MJRefreshHeader *cmp = [[self alloc] init]; 27 | [cmp setRefreshingTarget:target refreshingAction:action]; 28 | return cmp; 29 | } 30 | 31 | #pragma mark - 覆盖父类的方法 32 | - (void)prepare 33 | { 34 | [super prepare]; 35 | 36 | // 设置key 37 | self.lastUpdatedTimeKey = MJRefreshHeaderLastUpdatedTimeKey; 38 | 39 | // 设置高度 40 | self.mj_h = MJRefreshHeaderHeight; 41 | } 42 | 43 | - (void)placeSubviews 44 | { 45 | [super placeSubviews]; 46 | 47 | // 设置y值(当自己的高度发生改变了,肯定要重新调整Y值,所以放到placeSubviews方法中设置y值) 48 | self.mj_y = - self.mj_h - self.ignoredScrollViewContentInsetTop; 49 | } 50 | 51 | - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change 52 | { 53 | [super scrollViewContentOffsetDidChange:change]; 54 | 55 | // 在刷新的refreshing状态 56 | if (self.state == MJRefreshStateRefreshing) { 57 | if (self.window == nil) return; 58 | 59 | // sectionheader停留解决 60 | CGFloat insetT = - self.scrollView.mj_offsetY > _scrollViewOriginalInset.top ? - self.scrollView.mj_offsetY : _scrollViewOriginalInset.top; 61 | insetT = insetT > self.mj_h + _scrollViewOriginalInset.top ? self.mj_h + _scrollViewOriginalInset.top : insetT; 62 | self.scrollView.mj_insetT = insetT; 63 | 64 | self.insetTDelta = _scrollViewOriginalInset.top - insetT; 65 | return; 66 | } 67 | 68 | // 跳转到下一个控制器时,contentInset可能会变 69 | _scrollViewOriginalInset = self.scrollView.contentInset; 70 | 71 | // 当前的contentOffset 72 | CGFloat offsetY = self.scrollView.mj_offsetY; 73 | // 头部控件刚好出现的offsetY 74 | CGFloat happenOffsetY = - self.scrollViewOriginalInset.top; 75 | 76 | // 如果是向上滚动到看不见头部控件,直接返回 77 | // >= -> > 78 | if (offsetY > happenOffsetY) return; 79 | 80 | // 普通 和 即将刷新 的临界点 81 | CGFloat normal2pullingOffsetY = happenOffsetY - self.mj_h; 82 | CGFloat pullingPercent = (happenOffsetY - offsetY) / self.mj_h; 83 | 84 | if (self.scrollView.isDragging) { // 如果正在拖拽 85 | self.pullingPercent = pullingPercent; 86 | if (self.state == MJRefreshStateIdle && offsetY < normal2pullingOffsetY) { 87 | // 转为即将刷新状态 88 | self.state = MJRefreshStatePulling; 89 | } else if (self.state == MJRefreshStatePulling && offsetY >= normal2pullingOffsetY) { 90 | // 转为普通状态 91 | self.state = MJRefreshStateIdle; 92 | } 93 | } else if (self.state == MJRefreshStatePulling) {// 即将刷新 && 手松开 94 | // 开始刷新 95 | [self beginRefreshing]; 96 | } else if (pullingPercent < 1) { 97 | self.pullingPercent = pullingPercent; 98 | } 99 | } 100 | 101 | - (void)setState:(MJRefreshState)state 102 | { 103 | MJRefreshCheckState 104 | 105 | // 根据状态做事情 106 | if (state == MJRefreshStateIdle) { 107 | if (oldState != MJRefreshStateRefreshing) return; 108 | 109 | // 保存刷新时间 110 | [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:self.lastUpdatedTimeKey]; 111 | [[NSUserDefaults standardUserDefaults] synchronize]; 112 | 113 | // 恢复inset和offset 114 | [UIView animateWithDuration:MJRefreshSlowAnimationDuration animations:^{ 115 | self.scrollView.mj_insetT += self.insetTDelta; 116 | 117 | // 自动调整透明度 118 | if (self.isAutomaticallyChangeAlpha) self.alpha = 0.0; 119 | } completion:^(BOOL finished) { 120 | self.pullingPercent = 0.0; 121 | 122 | if (self.endRefreshingCompletionBlock) { 123 | self.endRefreshingCompletionBlock(); 124 | } 125 | }]; 126 | } else if (state == MJRefreshStateRefreshing) { 127 | dispatch_async(dispatch_get_main_queue(), ^{ 128 | [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ 129 | CGFloat top = self.scrollViewOriginalInset.top + self.mj_h; 130 | // 增加滚动区域top 131 | self.scrollView.mj_insetT = top; 132 | // 设置滚动位置 133 | [self.scrollView setContentOffset:CGPointMake(0, -top) animated:NO]; 134 | } completion:^(BOOL finished) { 135 | [self executeRefreshingCallback]; 136 | }]; 137 | }); 138 | } 139 | } 140 | 141 | #pragma mark - 公共方法 142 | - (void)endRefreshing 143 | { 144 | dispatch_async(dispatch_get_main_queue(), ^{ 145 | self.state = MJRefreshStateIdle; 146 | }); 147 | } 148 | 149 | - (NSDate *)lastUpdatedTime 150 | { 151 | return [[NSUserDefaults standardUserDefaults] objectForKey:self.lastUpdatedTimeKey]; 152 | } 153 | @end 154 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshAutoGifFooter.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshAutoStateFooter.h" 10 | 11 | @interface MJRefreshAutoGifFooter : MJRefreshAutoStateFooter 12 | @property (weak, nonatomic, readonly) UIImageView *gifView; 13 | 14 | /** 设置state状态下的动画图片images 动画持续时间duration*/ 15 | - (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state; 16 | - (void)setImages:(NSArray *)images forState:(MJRefreshState)state; 17 | @end 18 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshAutoGifFooter.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshAutoGifFooter.h" 10 | 11 | @interface MJRefreshAutoGifFooter() 12 | { 13 | __unsafe_unretained UIImageView *_gifView; 14 | } 15 | /** 所有状态对应的动画图片 */ 16 | @property (strong, nonatomic) NSMutableDictionary *stateImages; 17 | /** 所有状态对应的动画时间 */ 18 | @property (strong, nonatomic) NSMutableDictionary *stateDurations; 19 | @end 20 | 21 | @implementation MJRefreshAutoGifFooter 22 | #pragma mark - 懒加载 23 | - (UIImageView *)gifView 24 | { 25 | if (!_gifView) { 26 | UIImageView *gifView = [[UIImageView alloc] init]; 27 | [self addSubview:_gifView = gifView]; 28 | } 29 | return _gifView; 30 | } 31 | 32 | - (NSMutableDictionary *)stateImages 33 | { 34 | if (!_stateImages) { 35 | self.stateImages = [NSMutableDictionary dictionary]; 36 | } 37 | return _stateImages; 38 | } 39 | 40 | - (NSMutableDictionary *)stateDurations 41 | { 42 | if (!_stateDurations) { 43 | self.stateDurations = [NSMutableDictionary dictionary]; 44 | } 45 | return _stateDurations; 46 | } 47 | 48 | #pragma mark - 公共方法 49 | - (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state 50 | { 51 | if (images == nil) return; 52 | 53 | self.stateImages[@(state)] = images; 54 | self.stateDurations[@(state)] = @(duration); 55 | 56 | /* 根据图片设置控件的高度 */ 57 | UIImage *image = [images firstObject]; 58 | if (image.size.height > self.mj_h) { 59 | self.mj_h = image.size.height; 60 | } 61 | } 62 | 63 | - (void)setImages:(NSArray *)images forState:(MJRefreshState)state 64 | { 65 | [self setImages:images duration:images.count * 0.1 forState:state]; 66 | } 67 | 68 | #pragma mark - 实现父类的方法 69 | - (void)prepare 70 | { 71 | [super prepare]; 72 | 73 | // 初始化间距 74 | self.labelLeftInset = 20; 75 | } 76 | 77 | - (void)placeSubviews 78 | { 79 | [super placeSubviews]; 80 | 81 | if (self.gifView.constraints.count) return; 82 | 83 | self.gifView.frame = self.bounds; 84 | if (self.isRefreshingTitleHidden) { 85 | self.gifView.contentMode = UIViewContentModeCenter; 86 | } else { 87 | self.gifView.contentMode = UIViewContentModeRight; 88 | self.gifView.mj_w = self.mj_w * 0.5 - self.labelLeftInset - self.stateLabel.mj_textWith * 0.5; 89 | } 90 | } 91 | 92 | - (void)setState:(MJRefreshState)state 93 | { 94 | MJRefreshCheckState 95 | 96 | // 根据状态做事情 97 | if (state == MJRefreshStateRefreshing) { 98 | NSArray *images = self.stateImages[@(state)]; 99 | if (images.count == 0) return; 100 | [self.gifView stopAnimating]; 101 | 102 | self.gifView.hidden = NO; 103 | if (images.count == 1) { // 单张图片 104 | self.gifView.image = [images lastObject]; 105 | } else { // 多张图片 106 | self.gifView.animationImages = images; 107 | self.gifView.animationDuration = [self.stateDurations[@(state)] doubleValue]; 108 | [self.gifView startAnimating]; 109 | } 110 | } else if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) { 111 | [self.gifView stopAnimating]; 112 | self.gifView.hidden = YES; 113 | } 114 | } 115 | @end 116 | 117 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshAutoNormalFooter.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshAutoStateFooter.h" 10 | 11 | @interface MJRefreshAutoNormalFooter : MJRefreshAutoStateFooter 12 | /** 菊花的样式 */ 13 | @property (assign, nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle; 14 | @end 15 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshAutoNormalFooter.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshAutoNormalFooter.h" 10 | 11 | @interface MJRefreshAutoNormalFooter() 12 | @property (weak, nonatomic) UIActivityIndicatorView *loadingView; 13 | @end 14 | 15 | @implementation MJRefreshAutoNormalFooter 16 | #pragma mark - 懒加载子控件 17 | - (UIActivityIndicatorView *)loadingView 18 | { 19 | if (!_loadingView) { 20 | UIActivityIndicatorView *loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:self.activityIndicatorViewStyle]; 21 | loadingView.hidesWhenStopped = YES; 22 | [self addSubview:_loadingView = loadingView]; 23 | } 24 | return _loadingView; 25 | } 26 | 27 | - (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle 28 | { 29 | _activityIndicatorViewStyle = activityIndicatorViewStyle; 30 | 31 | self.loadingView = nil; 32 | [self setNeedsLayout]; 33 | } 34 | #pragma mark - 重写父类的方法 35 | - (void)prepare 36 | { 37 | [super prepare]; 38 | 39 | self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; 40 | } 41 | 42 | - (void)placeSubviews 43 | { 44 | [super placeSubviews]; 45 | 46 | if (self.loadingView.constraints.count) return; 47 | 48 | // 圈圈 49 | CGFloat loadingCenterX = self.mj_w * 0.5; 50 | if (!self.isRefreshingTitleHidden) { 51 | loadingCenterX -= self.stateLabel.mj_textWith * 0.5 + self.labelLeftInset; 52 | } 53 | CGFloat loadingCenterY = self.mj_h * 0.5; 54 | self.loadingView.center = CGPointMake(loadingCenterX, loadingCenterY); 55 | } 56 | 57 | - (void)setState:(MJRefreshState)state 58 | { 59 | MJRefreshCheckState 60 | 61 | // 根据状态做事情 62 | if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) { 63 | [self.loadingView stopAnimating]; 64 | } else if (state == MJRefreshStateRefreshing) { 65 | [self.loadingView startAnimating]; 66 | } 67 | } 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshAutoStateFooter.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/6/13. 6 | // Copyright © 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshAutoFooter.h" 10 | 11 | @interface MJRefreshAutoStateFooter : MJRefreshAutoFooter 12 | /** 文字距离圈圈、箭头的距离 */ 13 | @property (assign, nonatomic) CGFloat labelLeftInset; 14 | /** 显示刷新状态的label */ 15 | @property (weak, nonatomic, readonly) UILabel *stateLabel; 16 | 17 | /** 设置state状态下的文字 */ 18 | - (void)setTitle:(NSString *)title forState:(MJRefreshState)state; 19 | 20 | /** 隐藏刷新状态的文字 */ 21 | @property (assign, nonatomic, getter=isRefreshingTitleHidden) BOOL refreshingTitleHidden; 22 | @end 23 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshAutoStateFooter.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/6/13. 6 | // Copyright © 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshAutoStateFooter.h" 10 | 11 | @interface MJRefreshAutoStateFooter() 12 | { 13 | /** 显示刷新状态的label */ 14 | __unsafe_unretained UILabel *_stateLabel; 15 | } 16 | /** 所有状态对应的文字 */ 17 | @property (strong, nonatomic) NSMutableDictionary *stateTitles; 18 | @end 19 | 20 | @implementation MJRefreshAutoStateFooter 21 | #pragma mark - 懒加载 22 | - (NSMutableDictionary *)stateTitles 23 | { 24 | if (!_stateTitles) { 25 | self.stateTitles = [NSMutableDictionary dictionary]; 26 | } 27 | return _stateTitles; 28 | } 29 | 30 | - (UILabel *)stateLabel 31 | { 32 | if (!_stateLabel) { 33 | [self addSubview:_stateLabel = [UILabel mj_label]]; 34 | } 35 | return _stateLabel; 36 | } 37 | 38 | #pragma mark - 公共方法 39 | - (void)setTitle:(NSString *)title forState:(MJRefreshState)state 40 | { 41 | if (title == nil) return; 42 | self.stateTitles[@(state)] = title; 43 | self.stateLabel.text = self.stateTitles[@(self.state)]; 44 | } 45 | 46 | #pragma mark - 私有方法 47 | - (void)stateLabelClick 48 | { 49 | if (self.state == MJRefreshStateIdle) { 50 | [self beginRefreshing]; 51 | } 52 | } 53 | 54 | #pragma mark - 重写父类的方法 55 | - (void)prepare 56 | { 57 | [super prepare]; 58 | 59 | // 初始化间距 60 | self.labelLeftInset = MJRefreshLabelLeftInset; 61 | 62 | // 初始化文字 63 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshAutoFooterIdleText] forState:MJRefreshStateIdle]; 64 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshAutoFooterRefreshingText] forState:MJRefreshStateRefreshing]; 65 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshAutoFooterNoMoreDataText] forState:MJRefreshStateNoMoreData]; 66 | 67 | // 监听label 68 | self.stateLabel.userInteractionEnabled = YES; 69 | [self.stateLabel addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(stateLabelClick)]]; 70 | } 71 | 72 | - (void)placeSubviews 73 | { 74 | [super placeSubviews]; 75 | 76 | if (self.stateLabel.constraints.count) return; 77 | 78 | // 状态标签 79 | self.stateLabel.frame = self.bounds; 80 | } 81 | 82 | - (void)setState:(MJRefreshState)state 83 | { 84 | MJRefreshCheckState 85 | 86 | if (self.isRefreshingTitleHidden && state == MJRefreshStateRefreshing) { 87 | self.stateLabel.text = nil; 88 | } else { 89 | self.stateLabel.text = self.stateTitles[@(state)]; 90 | } 91 | } 92 | @end -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshBackGifFooter.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshBackStateFooter.h" 10 | 11 | @interface MJRefreshBackGifFooter : MJRefreshBackStateFooter 12 | @property (weak, nonatomic, readonly) UIImageView *gifView; 13 | 14 | /** 设置state状态下的动画图片images 动画持续时间duration*/ 15 | - (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state; 16 | - (void)setImages:(NSArray *)images forState:(MJRefreshState)state; 17 | @end 18 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshBackGifFooter.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshBackGifFooter.h" 10 | 11 | @interface MJRefreshBackGifFooter() 12 | { 13 | __unsafe_unretained UIImageView *_gifView; 14 | } 15 | /** 所有状态对应的动画图片 */ 16 | @property (strong, nonatomic) NSMutableDictionary *stateImages; 17 | /** 所有状态对应的动画时间 */ 18 | @property (strong, nonatomic) NSMutableDictionary *stateDurations; 19 | @end 20 | 21 | @implementation MJRefreshBackGifFooter 22 | #pragma mark - 懒加载 23 | - (UIImageView *)gifView 24 | { 25 | if (!_gifView) { 26 | UIImageView *gifView = [[UIImageView alloc] init]; 27 | [self addSubview:_gifView = gifView]; 28 | } 29 | return _gifView; 30 | } 31 | 32 | - (NSMutableDictionary *)stateImages 33 | { 34 | if (!_stateImages) { 35 | self.stateImages = [NSMutableDictionary dictionary]; 36 | } 37 | return _stateImages; 38 | } 39 | 40 | - (NSMutableDictionary *)stateDurations 41 | { 42 | if (!_stateDurations) { 43 | self.stateDurations = [NSMutableDictionary dictionary]; 44 | } 45 | return _stateDurations; 46 | } 47 | 48 | #pragma mark - 公共方法 49 | - (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state 50 | { 51 | if (images == nil) return; 52 | 53 | self.stateImages[@(state)] = images; 54 | self.stateDurations[@(state)] = @(duration); 55 | 56 | /* 根据图片设置控件的高度 */ 57 | UIImage *image = [images firstObject]; 58 | if (image.size.height > self.mj_h) { 59 | self.mj_h = image.size.height; 60 | } 61 | } 62 | 63 | - (void)setImages:(NSArray *)images forState:(MJRefreshState)state 64 | { 65 | [self setImages:images duration:images.count * 0.1 forState:state]; 66 | } 67 | 68 | #pragma mark - 实现父类的方法 69 | - (void)prepare 70 | { 71 | [super prepare]; 72 | 73 | // 初始化间距 74 | self.labelLeftInset = 20; 75 | } 76 | 77 | - (void)setPullingPercent:(CGFloat)pullingPercent 78 | { 79 | [super setPullingPercent:pullingPercent]; 80 | NSArray *images = self.stateImages[@(MJRefreshStateIdle)]; 81 | if (self.state != MJRefreshStateIdle || images.count == 0) return; 82 | [self.gifView stopAnimating]; 83 | NSUInteger index = images.count * pullingPercent; 84 | if (index >= images.count) index = images.count - 1; 85 | self.gifView.image = images[index]; 86 | } 87 | 88 | - (void)placeSubviews 89 | { 90 | [super placeSubviews]; 91 | 92 | if (self.gifView.constraints.count) return; 93 | 94 | self.gifView.frame = self.bounds; 95 | if (self.stateLabel.hidden) { 96 | self.gifView.contentMode = UIViewContentModeCenter; 97 | } else { 98 | self.gifView.contentMode = UIViewContentModeRight; 99 | self.gifView.mj_w = self.mj_w * 0.5 - self.labelLeftInset - self.stateLabel.mj_textWith * 0.5; 100 | } 101 | } 102 | 103 | - (void)setState:(MJRefreshState)state 104 | { 105 | MJRefreshCheckState 106 | 107 | // 根据状态做事情 108 | if (state == MJRefreshStatePulling || state == MJRefreshStateRefreshing) { 109 | NSArray *images = self.stateImages[@(state)]; 110 | if (images.count == 0) return; 111 | 112 | self.gifView.hidden = NO; 113 | [self.gifView stopAnimating]; 114 | if (images.count == 1) { // 单张图片 115 | self.gifView.image = [images lastObject]; 116 | } else { // 多张图片 117 | self.gifView.animationImages = images; 118 | self.gifView.animationDuration = [self.stateDurations[@(state)] doubleValue]; 119 | [self.gifView startAnimating]; 120 | } 121 | } else if (state == MJRefreshStateIdle) { 122 | self.gifView.hidden = NO; 123 | } else if (state == MJRefreshStateNoMoreData) { 124 | self.gifView.hidden = YES; 125 | } 126 | } 127 | @end 128 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshBackNormalFooter.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshBackStateFooter.h" 10 | 11 | @interface MJRefreshBackNormalFooter : MJRefreshBackStateFooter 12 | @property (weak, nonatomic, readonly) UIImageView *arrowView; 13 | /** 菊花的样式 */ 14 | @property (assign, nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle; 15 | @end 16 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshBackNormalFooter.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshBackNormalFooter.h" 10 | #import "NSBundle+MJRefresh.h" 11 | 12 | @interface MJRefreshBackNormalFooter() 13 | { 14 | // __unsafe_unretained UIImageView *_arrowView; 15 | } 16 | @property (weak, nonatomic) UIActivityIndicatorView *loadingView; 17 | @end 18 | 19 | @implementation MJRefreshBackNormalFooter 20 | //#pragma mark - 懒加载子控件 21 | //- (UIImageView *)arrowView 22 | //{ 23 | // if (!_arrowView) { 24 | // UIImageView *arrowView = [[UIImageView alloc] initWithImage:[NSBundle mj_arrowImage]]; 25 | // [self addSubview:_arrowView = arrowView]; 26 | // } 27 | // return _arrowView; 28 | //} 29 | 30 | 31 | - (UIActivityIndicatorView *)loadingView 32 | { 33 | if (!_loadingView) { 34 | UIActivityIndicatorView *loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:self.activityIndicatorViewStyle]; 35 | loadingView.hidesWhenStopped = YES; 36 | [self addSubview:_loadingView = loadingView]; 37 | } 38 | return _loadingView; 39 | } 40 | 41 | - (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle 42 | { 43 | _activityIndicatorViewStyle = activityIndicatorViewStyle; 44 | 45 | self.loadingView = nil; 46 | [self setNeedsLayout]; 47 | } 48 | #pragma mark - 重写父类的方法 49 | - (void)prepare 50 | { 51 | [super prepare]; 52 | 53 | self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; 54 | } 55 | 56 | - (void)placeSubviews 57 | { 58 | [super placeSubviews]; 59 | 60 | // 箭头的中心点 61 | CGFloat arrowCenterX = self.mj_w * 0.5; 62 | if (!self.stateLabel.hidden) { 63 | arrowCenterX -= self.labelLeftInset + self.stateLabel.mj_textWith * 0.5; 64 | } 65 | CGFloat arrowCenterY = self.mj_h * 0.5; 66 | CGPoint arrowCenter = CGPointMake(arrowCenterX, arrowCenterY); 67 | 68 | // 箭头 69 | if (self.arrowView.constraints.count == 0) { 70 | self.arrowView.mj_size = self.arrowView.image.size; 71 | self.arrowView.center = arrowCenter; 72 | } 73 | 74 | // 圈圈 75 | if (self.loadingView.constraints.count == 0) { 76 | self.loadingView.center = arrowCenter; 77 | } 78 | 79 | self.arrowView.tintColor = self.stateLabel.textColor; 80 | } 81 | 82 | - (void)setState:(MJRefreshState)state 83 | { 84 | MJRefreshCheckState 85 | 86 | // 根据状态做事情 87 | if (state == MJRefreshStateIdle) { 88 | if (oldState == MJRefreshStateRefreshing) { 89 | self.arrowView.transform = CGAffineTransformMakeRotation(0.000001 - M_PI); 90 | [UIView animateWithDuration:MJRefreshSlowAnimationDuration animations:^{ 91 | self.loadingView.alpha = 0.0; 92 | } completion:^(BOOL finished) { 93 | self.loadingView.alpha = 1.0; 94 | [self.loadingView stopAnimating]; 95 | 96 | self.arrowView.hidden = NO; 97 | }]; 98 | } else { 99 | self.arrowView.hidden = NO; 100 | [self.loadingView stopAnimating]; 101 | [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ 102 | self.arrowView.transform = CGAffineTransformMakeRotation(0.000001 - M_PI); 103 | }]; 104 | } 105 | } else if (state == MJRefreshStatePulling) { 106 | self.arrowView.hidden = NO; 107 | [self.loadingView stopAnimating]; 108 | [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ 109 | self.arrowView.transform = CGAffineTransformIdentity; 110 | }]; 111 | } else if (state == MJRefreshStateRefreshing) { 112 | self.arrowView.hidden = YES; 113 | [self.loadingView startAnimating]; 114 | } else if (state == MJRefreshStateNoMoreData) { 115 | self.arrowView.hidden = YES; 116 | [self.loadingView stopAnimating]; 117 | } 118 | } 119 | 120 | @end 121 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshBackStateFooter.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/6/13. 6 | // Copyright © 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshBackFooter.h" 10 | 11 | @interface MJRefreshBackStateFooter : MJRefreshBackFooter 12 | /** 文字距离圈圈、箭头的距离 */ 13 | @property (assign, nonatomic) CGFloat labelLeftInset; 14 | /** 显示刷新状态的label */ 15 | @property (weak, nonatomic, readonly) UILabel *stateLabel; 16 | /** 设置state状态下的文字 */ 17 | - (void)setTitle:(NSString *)title forState:(MJRefreshState)state; 18 | 19 | /** 获取state状态下的title */ 20 | - (NSString *)titleForState:(MJRefreshState)state; 21 | @end 22 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshBackStateFooter.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/6/13. 6 | // Copyright © 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshBackStateFooter.h" 10 | 11 | @interface MJRefreshBackStateFooter() 12 | { 13 | /** 显示刷新状态的label */ 14 | __unsafe_unretained UILabel *_stateLabel; 15 | } 16 | /** 所有状态对应的文字 */ 17 | @property (strong, nonatomic) NSMutableDictionary *stateTitles; 18 | @end 19 | 20 | @implementation MJRefreshBackStateFooter 21 | #pragma mark - 懒加载 22 | - (NSMutableDictionary *)stateTitles 23 | { 24 | if (!_stateTitles) { 25 | self.stateTitles = [NSMutableDictionary dictionary]; 26 | } 27 | return _stateTitles; 28 | } 29 | 30 | - (UILabel *)stateLabel 31 | { 32 | if (!_stateLabel) { 33 | [self addSubview:_stateLabel = [UILabel mj_label]]; 34 | } 35 | return _stateLabel; 36 | } 37 | 38 | #pragma mark - 公共方法 39 | - (void)setTitle:(NSString *)title forState:(MJRefreshState)state 40 | { 41 | if (title == nil) return; 42 | self.stateTitles[@(state)] = title; 43 | self.stateLabel.text = self.stateTitles[@(self.state)]; 44 | } 45 | 46 | - (NSString *)titleForState:(MJRefreshState)state { 47 | return self.stateTitles[@(state)]; 48 | } 49 | 50 | #pragma mark - 重写父类的方法 51 | - (void)prepare 52 | { 53 | [super prepare]; 54 | 55 | // 初始化间距 56 | self.labelLeftInset = MJRefreshLabelLeftInset; 57 | 58 | // 初始化文字 59 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterIdleText] forState:MJRefreshStateIdle]; 60 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterPullingText] forState:MJRefreshStatePulling]; 61 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterRefreshingText] forState:MJRefreshStateRefreshing]; 62 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterNoMoreDataText] forState:MJRefreshStateNoMoreData]; 63 | } 64 | 65 | - (void)placeSubviews 66 | { 67 | [super placeSubviews]; 68 | 69 | if (self.stateLabel.constraints.count) return; 70 | 71 | // 状态标签 72 | self.stateLabel.frame = self.bounds; 73 | } 74 | 75 | - (void)setState:(MJRefreshState)state 76 | { 77 | MJRefreshCheckState 78 | 79 | // 设置状态文字 80 | self.stateLabel.text = self.stateTitles[@(state)]; 81 | } 82 | @end 83 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Custom/Header/MJRefreshGifHeader.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshGifHeader.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshStateHeader.h" 10 | 11 | @interface MJRefreshGifHeader : MJRefreshStateHeader 12 | @property (weak, nonatomic, readonly) UIImageView *gifView; 13 | 14 | /** 设置state状态下的动画图片images 动画持续时间duration*/ 15 | - (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state; 16 | - (void)setImages:(NSArray *)images forState:(MJRefreshState)state; 17 | @end 18 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Custom/Header/MJRefreshGifHeader.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshGifHeader.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshGifHeader.h" 10 | 11 | @interface MJRefreshGifHeader() 12 | { 13 | __unsafe_unretained UIImageView *_gifView; 14 | } 15 | /** 所有状态对应的动画图片 */ 16 | @property (strong, nonatomic) NSMutableDictionary *stateImages; 17 | /** 所有状态对应的动画时间 */ 18 | @property (strong, nonatomic) NSMutableDictionary *stateDurations; 19 | @end 20 | 21 | @implementation MJRefreshGifHeader 22 | #pragma mark - 懒加载 23 | - (UIImageView *)gifView 24 | { 25 | if (!_gifView) { 26 | UIImageView *gifView = [[UIImageView alloc] init]; 27 | [self addSubview:_gifView = gifView]; 28 | } 29 | return _gifView; 30 | } 31 | 32 | - (NSMutableDictionary *)stateImages 33 | { 34 | if (!_stateImages) { 35 | self.stateImages = [NSMutableDictionary dictionary]; 36 | } 37 | return _stateImages; 38 | } 39 | 40 | - (NSMutableDictionary *)stateDurations 41 | { 42 | if (!_stateDurations) { 43 | self.stateDurations = [NSMutableDictionary dictionary]; 44 | } 45 | return _stateDurations; 46 | } 47 | 48 | #pragma mark - 公共方法 49 | - (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state 50 | { 51 | if (images == nil) return; 52 | 53 | self.stateImages[@(state)] = images; 54 | self.stateDurations[@(state)] = @(duration); 55 | 56 | /* 根据图片设置控件的高度 */ 57 | UIImage *image = [images firstObject]; 58 | if (image.size.height > self.mj_h) { 59 | self.mj_h = image.size.height; 60 | } 61 | } 62 | 63 | - (void)setImages:(NSArray *)images forState:(MJRefreshState)state 64 | { 65 | [self setImages:images duration:images.count * 0.1 forState:state]; 66 | } 67 | 68 | #pragma mark - 实现父类的方法 69 | - (void)prepare 70 | { 71 | [super prepare]; 72 | 73 | // 初始化间距 74 | self.labelLeftInset = 20; 75 | } 76 | 77 | - (void)setPullingPercent:(CGFloat)pullingPercent 78 | { 79 | [super setPullingPercent:pullingPercent]; 80 | NSArray *images = self.stateImages[@(MJRefreshStateIdle)]; 81 | if (self.state != MJRefreshStateIdle || images.count == 0) return; 82 | // 停止动画 83 | [self.gifView stopAnimating]; 84 | // 设置当前需要显示的图片 85 | NSUInteger index = images.count * pullingPercent; 86 | if (index >= images.count) index = images.count - 1; 87 | self.gifView.image = images[index]; 88 | } 89 | 90 | - (void)placeSubviews 91 | { 92 | [super placeSubviews]; 93 | 94 | if (self.gifView.constraints.count) return; 95 | 96 | self.gifView.frame = self.bounds; 97 | if (self.stateLabel.hidden && self.lastUpdatedTimeLabel.hidden) { 98 | self.gifView.contentMode = UIViewContentModeCenter; 99 | } else { 100 | self.gifView.contentMode = UIViewContentModeRight; 101 | 102 | CGFloat stateWidth = self.stateLabel.mj_textWith; 103 | CGFloat timeWidth = 0.0; 104 | if (!self.lastUpdatedTimeLabel.hidden) { 105 | timeWidth = self.lastUpdatedTimeLabel.mj_textWith; 106 | } 107 | CGFloat textWidth = MAX(stateWidth, timeWidth); 108 | self.gifView.mj_w = self.mj_w * 0.5 - textWidth * 0.5 - self.labelLeftInset; 109 | } 110 | } 111 | 112 | - (void)setState:(MJRefreshState)state 113 | { 114 | MJRefreshCheckState 115 | 116 | // 根据状态做事情 117 | if (state == MJRefreshStatePulling || state == MJRefreshStateRefreshing) { 118 | NSArray *images = self.stateImages[@(state)]; 119 | if (images.count == 0) return; 120 | 121 | [self.gifView stopAnimating]; 122 | if (images.count == 1) { // 单张图片 123 | self.gifView.image = [images lastObject]; 124 | } else { // 多张图片 125 | self.gifView.animationImages = images; 126 | self.gifView.animationDuration = [self.stateDurations[@(state)] doubleValue]; 127 | [self.gifView startAnimating]; 128 | } 129 | } else if (state == MJRefreshStateIdle) { 130 | [self.gifView stopAnimating]; 131 | } 132 | } 133 | @end 134 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Custom/Header/MJRefreshNormalHeader.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshNormalHeader.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshStateHeader.h" 10 | 11 | @interface MJRefreshNormalHeader : MJRefreshStateHeader 12 | @property (weak, nonatomic, readonly) UIImageView *arrowView; 13 | /** 菊花的样式 */ 14 | @property (assign, nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle; 15 | @end 16 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Custom/Header/MJRefreshNormalHeader.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshNormalHeader.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshNormalHeader.h" 10 | #import "NSBundle+MJRefresh.h" 11 | 12 | @interface MJRefreshNormalHeader() 13 | { 14 | // __unsafe_unretained UIImageView *_arrowView; 15 | } 16 | @property (weak, nonatomic) UIActivityIndicatorView *loadingView; 17 | @end 18 | 19 | @implementation MJRefreshNormalHeader 20 | //#pragma mark - 懒加载子控件 21 | //- (UIImageView *)arrowView 22 | //{ 23 | // if (!_arrowView) { 24 | // UIImageView *arrowView = [[UIImageView alloc] initWithImage:[NSBundle mj_arrowImage]]; 25 | // [self addSubview:_arrowView = arrowView]; 26 | // } 27 | // return _arrowView; 28 | //} 29 | 30 | - (UIActivityIndicatorView *)loadingView 31 | { 32 | if (!_loadingView) { 33 | UIActivityIndicatorView *loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:self.activityIndicatorViewStyle]; 34 | loadingView.hidesWhenStopped = YES; 35 | [self addSubview:_loadingView = loadingView]; 36 | } 37 | return _loadingView; 38 | } 39 | 40 | #pragma mark - 公共方法 41 | - (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle 42 | { 43 | _activityIndicatorViewStyle = activityIndicatorViewStyle; 44 | 45 | self.loadingView = nil; 46 | [self setNeedsLayout]; 47 | } 48 | 49 | #pragma mark - 重写父类的方法 50 | - (void)prepare 51 | { 52 | [super prepare]; 53 | 54 | self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; 55 | } 56 | 57 | - (void)placeSubviews 58 | { 59 | [super placeSubviews]; 60 | 61 | // 箭头的中心点 62 | CGFloat arrowCenterX = self.mj_w * 0.5; 63 | if (!self.stateLabel.hidden) { 64 | CGFloat stateWidth = self.stateLabel.mj_textWith; 65 | CGFloat timeWidth = 0.0; 66 | if (!self.lastUpdatedTimeLabel.hidden) { 67 | timeWidth = self.lastUpdatedTimeLabel.mj_textWith; 68 | } 69 | CGFloat textWidth = MAX(stateWidth, timeWidth); 70 | arrowCenterX -= textWidth / 2 + self.labelLeftInset; 71 | } 72 | CGFloat arrowCenterY = self.mj_h * 0.5; 73 | CGPoint arrowCenter = CGPointMake(arrowCenterX, arrowCenterY); 74 | 75 | // 箭头 76 | if (self.arrowView.constraints.count == 0) { 77 | self.arrowView.mj_size = self.arrowView.image.size; 78 | self.arrowView.center = arrowCenter; 79 | } 80 | 81 | // 圈圈 82 | if (self.loadingView.constraints.count == 0) { 83 | self.loadingView.center = arrowCenter; 84 | } 85 | 86 | self.arrowView.tintColor = self.stateLabel.textColor; 87 | } 88 | 89 | - (void)setState:(MJRefreshState)state 90 | { 91 | MJRefreshCheckState 92 | 93 | // 根据状态做事情 94 | if (state == MJRefreshStateIdle) { 95 | if (oldState == MJRefreshStateRefreshing) { 96 | self.arrowView.transform = CGAffineTransformIdentity; 97 | 98 | [UIView animateWithDuration:MJRefreshSlowAnimationDuration animations:^{ 99 | self.loadingView.alpha = 0.0; 100 | } completion:^(BOOL finished) { 101 | // 如果执行完动画发现不是idle状态,就直接返回,进入其他状态 102 | if (self.state != MJRefreshStateIdle) return; 103 | 104 | self.loadingView.alpha = 1.0; 105 | [self.loadingView stopAnimating]; 106 | self.arrowView.hidden = NO; 107 | }]; 108 | } else { 109 | [self.loadingView stopAnimating]; 110 | self.arrowView.hidden = NO; 111 | [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ 112 | self.arrowView.transform = CGAffineTransformIdentity; 113 | }]; 114 | } 115 | } else if (state == MJRefreshStatePulling) { 116 | [self.loadingView stopAnimating]; 117 | self.arrowView.hidden = NO; 118 | [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ 119 | self.arrowView.transform = CGAffineTransformMakeRotation(0.000001 - M_PI); 120 | }]; 121 | } else if (state == MJRefreshStateRefreshing) { 122 | self.loadingView.alpha = 1.0; // 防止refreshing -> idle的动画完毕动作没有被执行 123 | [self.loadingView startAnimating]; 124 | self.arrowView.hidden = YES; 125 | } 126 | } 127 | @end 128 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Custom/Header/MJRefreshStateHeader.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshStateHeader.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshHeader.h" 10 | 11 | @interface MJRefreshStateHeader : MJRefreshHeader 12 | #pragma mark - 刷新时间相关 13 | /** 利用这个block来决定显示的更新时间文字 */ 14 | @property (copy, nonatomic) NSString *(^lastUpdatedTimeText)(NSDate *lastUpdatedTime); 15 | /** 显示上一次刷新时间的label */ 16 | @property (weak, nonatomic, readonly) UILabel *lastUpdatedTimeLabel; 17 | 18 | #pragma mark - 状态相关 19 | /** 文字距离圈圈、箭头的距离 */ 20 | @property (assign, nonatomic) CGFloat labelLeftInset; 21 | /** 显示刷新状态的label */ 22 | @property (weak, nonatomic, readonly) UILabel *stateLabel; 23 | /** 设置state状态下的文字 */ 24 | - (void)setTitle:(NSString *)title forState:(MJRefreshState)state; 25 | @end 26 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/Custom/Header/MJRefreshStateHeader.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshStateHeader.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshStateHeader.h" 10 | 11 | @interface MJRefreshStateHeader() 12 | { 13 | /** 显示上一次刷新时间的label */ 14 | __unsafe_unretained UILabel *_lastUpdatedTimeLabel; 15 | /** 显示刷新状态的label */ 16 | __unsafe_unretained UILabel *_stateLabel; 17 | } 18 | /** 所有状态对应的文字 */ 19 | @property (strong, nonatomic) NSMutableDictionary *stateTitles; 20 | @end 21 | 22 | @implementation MJRefreshStateHeader 23 | #pragma mark - 懒加载 24 | - (NSMutableDictionary *)stateTitles 25 | { 26 | if (!_stateTitles) { 27 | self.stateTitles = [NSMutableDictionary dictionary]; 28 | } 29 | return _stateTitles; 30 | } 31 | 32 | - (UILabel *)stateLabel 33 | { 34 | if (!_stateLabel) { 35 | [self addSubview:_stateLabel = [UILabel mj_label]]; 36 | } 37 | return _stateLabel; 38 | } 39 | 40 | - (UILabel *)lastUpdatedTimeLabel 41 | { 42 | if (!_lastUpdatedTimeLabel) { 43 | [self addSubview:_lastUpdatedTimeLabel = [UILabel mj_label]]; 44 | } 45 | return _lastUpdatedTimeLabel; 46 | } 47 | 48 | #pragma mark - 公共方法 49 | - (void)setTitle:(NSString *)title forState:(MJRefreshState)state 50 | { 51 | if (title == nil) return; 52 | self.stateTitles[@(state)] = title; 53 | self.stateLabel.text = self.stateTitles[@(self.state)]; 54 | } 55 | 56 | #pragma mark - 日历获取在9.x之后的系统使用currentCalendar会出异常。在8.0之后使用系统新API。 57 | - (NSCalendar *)currentCalendar { 58 | if ([NSCalendar respondsToSelector:@selector(calendarWithIdentifier:)]) { 59 | return [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian]; 60 | } 61 | return [NSCalendar currentCalendar]; 62 | } 63 | 64 | #pragma mark key的处理 65 | - (void)setLastUpdatedTimeKey:(NSString *)lastUpdatedTimeKey 66 | { 67 | [super setLastUpdatedTimeKey:lastUpdatedTimeKey]; 68 | 69 | // 如果label隐藏了,就不用再处理 70 | if (self.lastUpdatedTimeLabel.hidden) return; 71 | 72 | NSDate *lastUpdatedTime = [[NSUserDefaults standardUserDefaults] objectForKey:lastUpdatedTimeKey]; 73 | 74 | // 如果有block 75 | if (self.lastUpdatedTimeText) { 76 | self.lastUpdatedTimeLabel.text = self.lastUpdatedTimeText(lastUpdatedTime); 77 | return; 78 | } 79 | 80 | if (lastUpdatedTime) { 81 | // 1.获得年月日 82 | NSCalendar *calendar = [self currentCalendar]; 83 | NSUInteger unitFlags = NSCalendarUnitYear| NSCalendarUnitMonth | NSCalendarUnitDay |NSCalendarUnitHour |NSCalendarUnitMinute; 84 | NSDateComponents *cmp1 = [calendar components:unitFlags fromDate:lastUpdatedTime]; 85 | NSDateComponents *cmp2 = [calendar components:unitFlags fromDate:[NSDate date]]; 86 | 87 | // 2.格式化日期 88 | NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 89 | BOOL isToday = NO; 90 | if ([cmp1 day] == [cmp2 day]) { // 今天 91 | formatter.dateFormat = @" HH:mm"; 92 | isToday = YES; 93 | } else if ([cmp1 year] == [cmp2 year]) { // 今年 94 | formatter.dateFormat = @"MM-dd HH:mm"; 95 | } else { 96 | formatter.dateFormat = @"yyyy-MM-dd HH:mm"; 97 | } 98 | NSString *time = [formatter stringFromDate:lastUpdatedTime]; 99 | 100 | // 3.显示日期 101 | self.lastUpdatedTimeLabel.text = [NSString stringWithFormat:@"%@%@%@", 102 | [NSBundle mj_localizedStringForKey:MJRefreshHeaderLastTimeText], 103 | isToday ? [NSBundle mj_localizedStringForKey:MJRefreshHeaderDateTodayText] : @"", 104 | time]; 105 | } else { 106 | self.lastUpdatedTimeLabel.text = [NSString stringWithFormat:@"%@%@", 107 | [NSBundle mj_localizedStringForKey:MJRefreshHeaderLastTimeText], 108 | [NSBundle mj_localizedStringForKey:MJRefreshHeaderNoneLastDateText]]; 109 | } 110 | } 111 | 112 | #pragma mark - 覆盖父类的方法 113 | - (void)prepare 114 | { 115 | [super prepare]; 116 | 117 | // 初始化间距 118 | self.labelLeftInset = MJRefreshLabelLeftInset; 119 | 120 | // 初始化文字 121 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshHeaderIdleText] forState:MJRefreshStateIdle]; 122 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshHeaderPullingText] forState:MJRefreshStatePulling]; 123 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshHeaderRefreshingText] forState:MJRefreshStateRefreshing]; 124 | } 125 | 126 | - (void)placeSubviews 127 | { 128 | [super placeSubviews]; 129 | 130 | if (self.stateLabel.hidden) return; 131 | 132 | BOOL noConstrainsOnStatusLabel = self.stateLabel.constraints.count == 0; 133 | 134 | if (self.lastUpdatedTimeLabel.hidden) { 135 | // 状态 136 | if (noConstrainsOnStatusLabel) self.stateLabel.frame = self.bounds; 137 | } else { 138 | CGFloat stateLabelH = self.mj_h * 0.5; 139 | // 状态 140 | if (noConstrainsOnStatusLabel) { 141 | self.stateLabel.mj_x = 0; 142 | self.stateLabel.mj_y = 0; 143 | self.stateLabel.mj_w = self.mj_w; 144 | self.stateLabel.mj_h = stateLabelH; 145 | } 146 | 147 | // 更新时间 148 | if (self.lastUpdatedTimeLabel.constraints.count == 0) { 149 | self.lastUpdatedTimeLabel.mj_x = 0; 150 | self.lastUpdatedTimeLabel.mj_y = stateLabelH; 151 | self.lastUpdatedTimeLabel.mj_w = self.mj_w; 152 | self.lastUpdatedTimeLabel.mj_h = self.mj_h - self.lastUpdatedTimeLabel.mj_y; 153 | } 154 | } 155 | } 156 | 157 | - (void)setState:(MJRefreshState)state 158 | { 159 | MJRefreshCheckState 160 | 161 | // 设置状态文字 162 | self.stateLabel.text = self.stateTitles[@(state)]; 163 | 164 | // 重新设置key(重新显示时间) 165 | self.lastUpdatedTimeKey = self.lastUpdatedTimeKey; 166 | } 167 | @end 168 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/MJRefresh.bundle/arrow@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/purejf/CustomTableViewController/ef7bce4adc4bf3fba052bab51a2d30ee7982e9a5/CustomTableVc/Charles/MJRefresh/MJRefresh/MJRefresh.bundle/arrow@2x.png -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/MJRefresh.bundle/en.lproj/Localizable.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/purejf/CustomTableViewController/ef7bce4adc4bf3fba052bab51a2d30ee7982e9a5/CustomTableVc/Charles/MJRefresh/MJRefresh/MJRefresh.bundle/en.lproj/Localizable.strings -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/MJRefresh.bundle/zh-Hans.lproj/Localizable.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/purejf/CustomTableViewController/ef7bce4adc4bf3fba052bab51a2d30ee7982e9a5/CustomTableVc/Charles/MJRefresh/MJRefresh/MJRefresh.bundle/zh-Hans.lproj/Localizable.strings -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/MJRefresh.bundle/zh-Hant.lproj/Localizable.strings: -------------------------------------------------------------------------------- 1 | "MJRefreshHeaderIdleText" = "下拉可以刷新"; 2 | "MJRefreshHeaderPullingText" = "鬆開立即刷新"; 3 | "MJRefreshHeaderRefreshingText" = "正在刷新數據中..."; 4 | 5 | "MJRefreshAutoFooterIdleText" = "點擊或上拉加載更多"; 6 | "MJRefreshAutoFooterRefreshingText" = "正在加載更多的數據..."; 7 | "MJRefreshAutoFooterNoMoreDataText" = "已經全部加載完畢"; 8 | 9 | "MJRefreshBackFooterIdleText" = "上拉可以加載更多"; 10 | "MJRefreshBackFooterPullingText" = "鬆開立即加載更多"; 11 | "MJRefreshBackFooterRefreshingText" = "正在加載更多的數據..."; 12 | "MJRefreshBackFooterNoMoreDataText" = "已經全部加載完畢"; 13 | 14 | "MJRefreshHeaderLastTimeText" = "最後更新:"; 15 | "MJRefreshHeaderDateTodayText" = "今天"; 16 | "MJRefreshHeaderNoneLastDateText" = "無記錄"; 17 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/MJRefresh.h: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: 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 3 | 4 | #import "UIScrollView+MJRefresh.h" 5 | #import "UIScrollView+MJExtension.h" 6 | #import "UIView+MJExtension.h" 7 | 8 | #import "MJRefreshNormalHeader.h" 9 | #import "MJRefreshGifHeader.h" 10 | 11 | #import "MJRefreshBackNormalFooter.h" 12 | #import "MJRefreshBackGifFooter.h" 13 | #import "MJRefreshAutoNormalFooter.h" 14 | #import "MJRefreshAutoGifFooter.h" -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/MJRefreshConst.h: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: 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 3 | #import 4 | #import 5 | 6 | // 弱引用 7 | #define MJWeakSelf __weak typeof(self) weakSelf = self; 8 | 9 | // 日志输出 10 | #ifdef DEBUG 11 | #define MJRefreshLog(...) NSLog(__VA_ARGS__) 12 | #else 13 | #define MJRefreshLog(...) 14 | #endif 15 | 16 | // 过期提醒 17 | #define MJRefreshDeprecated(instead) NS_DEPRECATED(2_0, 2_0, 2_0, 2_0, instead) 18 | 19 | // 运行时objc_msgSend 20 | #define MJRefreshMsgSend(...) ((void (*)(void *, SEL, UIView *))objc_msgSend)(__VA_ARGS__) 21 | #define MJRefreshMsgTarget(target) (__bridge void *)(target) 22 | 23 | // RGB颜色 24 | #define MJRefreshColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0] 25 | 26 | // 文字颜色 27 | #define MJRefreshLabelTextColor MJRefreshColor(90, 90, 90) 28 | 29 | // 字体大小 30 | #define MJRefreshLabelFont [UIFont boldSystemFontOfSize:14] 31 | 32 | // 常量 33 | UIKIT_EXTERN const CGFloat MJRefreshLabelLeftInset; 34 | UIKIT_EXTERN const CGFloat MJRefreshHeaderHeight; 35 | UIKIT_EXTERN const CGFloat MJRefreshFooterHeight; 36 | UIKIT_EXTERN const CGFloat MJRefreshFastAnimationDuration; 37 | UIKIT_EXTERN const CGFloat MJRefreshSlowAnimationDuration; 38 | 39 | UIKIT_EXTERN NSString *const MJRefreshKeyPathContentOffset; 40 | UIKIT_EXTERN NSString *const MJRefreshKeyPathContentSize; 41 | UIKIT_EXTERN NSString *const MJRefreshKeyPathContentInset; 42 | UIKIT_EXTERN NSString *const MJRefreshKeyPathPanState; 43 | 44 | UIKIT_EXTERN NSString *const MJRefreshHeaderLastUpdatedTimeKey; 45 | 46 | UIKIT_EXTERN NSString *const MJRefreshHeaderIdleText; 47 | UIKIT_EXTERN NSString *const MJRefreshHeaderPullingText; 48 | UIKIT_EXTERN NSString *const MJRefreshHeaderRefreshingText; 49 | 50 | UIKIT_EXTERN NSString *const MJRefreshAutoFooterIdleText; 51 | UIKIT_EXTERN NSString *const MJRefreshAutoFooterRefreshingText; 52 | UIKIT_EXTERN NSString *const MJRefreshAutoFooterNoMoreDataText; 53 | 54 | UIKIT_EXTERN NSString *const MJRefreshBackFooterIdleText; 55 | UIKIT_EXTERN NSString *const MJRefreshBackFooterPullingText; 56 | UIKIT_EXTERN NSString *const MJRefreshBackFooterRefreshingText; 57 | UIKIT_EXTERN NSString *const MJRefreshBackFooterNoMoreDataText; 58 | 59 | UIKIT_EXTERN NSString *const MJRefreshHeaderLastTimeText; 60 | UIKIT_EXTERN NSString *const MJRefreshHeaderDateTodayText; 61 | UIKIT_EXTERN NSString *const MJRefreshHeaderNoneLastDateText; 62 | 63 | // 状态检查 64 | #define MJRefreshCheckState \ 65 | MJRefreshState oldState = self.state; \ 66 | if (state == oldState) return; \ 67 | [super setState:state]; 68 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/MJRefreshConst.m: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: 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 3 | #import 4 | 5 | const CGFloat MJRefreshLabelLeftInset = 25; 6 | const CGFloat MJRefreshHeaderHeight = 54.0; 7 | const CGFloat MJRefreshFooterHeight = 44.0; 8 | const CGFloat MJRefreshFastAnimationDuration = 0.25; 9 | const CGFloat MJRefreshSlowAnimationDuration = 0.4; 10 | 11 | NSString *const MJRefreshKeyPathContentOffset = @"contentOffset"; 12 | NSString *const MJRefreshKeyPathContentInset = @"contentInset"; 13 | NSString *const MJRefreshKeyPathContentSize = @"contentSize"; 14 | NSString *const MJRefreshKeyPathPanState = @"state"; 15 | 16 | NSString *const MJRefreshHeaderLastUpdatedTimeKey = @"MJRefreshHeaderLastUpdatedTimeKey"; 17 | 18 | NSString *const MJRefreshHeaderIdleText = @"MJRefreshHeaderIdleText"; 19 | NSString *const MJRefreshHeaderPullingText = @"MJRefreshHeaderPullingText"; 20 | NSString *const MJRefreshHeaderRefreshingText = @"MJRefreshHeaderRefreshingText"; 21 | 22 | NSString *const MJRefreshAutoFooterIdleText = @"MJRefreshAutoFooterIdleText"; 23 | NSString *const MJRefreshAutoFooterRefreshingText = @"MJRefreshAutoFooterRefreshingText"; 24 | NSString *const MJRefreshAutoFooterNoMoreDataText = @"MJRefreshAutoFooterNoMoreDataText"; 25 | 26 | NSString *const MJRefreshBackFooterIdleText = @"MJRefreshBackFooterIdleText"; 27 | NSString *const MJRefreshBackFooterPullingText = @"MJRefreshBackFooterPullingText"; 28 | NSString *const MJRefreshBackFooterRefreshingText = @"MJRefreshBackFooterRefreshingText"; 29 | NSString *const MJRefreshBackFooterNoMoreDataText = @"MJRefreshBackFooterNoMoreDataText"; 30 | 31 | NSString *const MJRefreshHeaderLastTimeText = @"MJRefreshHeaderLastTimeText"; 32 | NSString *const MJRefreshHeaderDateTodayText = @"MJRefreshHeaderDateTodayText"; 33 | NSString *const MJRefreshHeaderNoneLastDateText = @"MJRefreshHeaderNoneLastDateText"; -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/NSBundle+MJRefresh.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSBundle+MJRefresh.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 16/6/13. 6 | // Copyright © 2016年 小码哥. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSBundle (MJRefresh) 12 | + (instancetype)mj_refreshBundle; 13 | //+ (UIImage *)mj_arrowImage; 14 | + (NSString *)mj_localizedStringForKey:(NSString *)key value:(NSString *)value; 15 | + (NSString *)mj_localizedStringForKey:(NSString *)key; 16 | @end 17 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/NSBundle+MJRefresh.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSBundle+MJRefresh.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 16/6/13. 6 | // Copyright © 2016年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "NSBundle+MJRefresh.h" 10 | #import "MJRefreshComponent.h" 11 | 12 | @implementation NSBundle (MJRefresh) 13 | + (instancetype)mj_refreshBundle 14 | { 15 | static NSBundle *refreshBundle = nil; 16 | if (refreshBundle == nil) { 17 | // 这里不使用mainBundle是为了适配pod 1.x和0.x 18 | refreshBundle = [NSBundle bundleWithPath:[[NSBundle bundleForClass:[MJRefreshComponent class]] pathForResource:@"MJRefresh" ofType:@"bundle"]]; 19 | } 20 | return refreshBundle; 21 | } 22 | 23 | + (UIImage *)mj_arrowImage 24 | { 25 | static UIImage *arrowImage = nil; 26 | if (arrowImage == nil) { 27 | arrowImage = [[UIImage imageWithContentsOfFile:[[self mj_refreshBundle] pathForResource:@"arrow@2x" ofType:@"png"]] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 28 | } 29 | return arrowImage; 30 | } 31 | 32 | + (NSString *)mj_localizedStringForKey:(NSString *)key 33 | { 34 | return [self mj_localizedStringForKey:key value:nil]; 35 | } 36 | 37 | + (NSString *)mj_localizedStringForKey:(NSString *)key value:(NSString *)value 38 | { 39 | static NSBundle *bundle = nil; 40 | if (bundle == nil) { 41 | // (iOS获取的语言字符串比较不稳定)目前框架只处理en、zh-Hans、zh-Hant三种情况,其他按照系统默认处理 42 | NSString *language = [NSLocale preferredLanguages].firstObject; 43 | if ([language hasPrefix:@"en"]) { 44 | language = @"en"; 45 | } else if ([language hasPrefix:@"zh"]) { 46 | if ([language rangeOfString:@"Hans"].location != NSNotFound) { 47 | language = @"zh-Hans"; // 简体中文 48 | } else { // zh-Hant\zh-HK\zh-TW 49 | language = @"zh-Hant"; // 繁體中文 50 | } 51 | } else { 52 | language = @"en"; 53 | } 54 | 55 | // 从MJRefresh.bundle中查找资源 56 | bundle = [NSBundle bundleWithPath:[[NSBundle mj_refreshBundle] pathForResource:language ofType:@"lproj"]]; 57 | } 58 | value = [bundle localizedStringForKey:key value:value table:nil]; 59 | return [[NSBundle mainBundle] localizedStringForKey:key value:value table:nil]; 60 | } 61 | @end 62 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/UIScrollView+MJExtension.h: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: 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 3 | // UIScrollView+Extension.h 4 | // MJRefreshExample 5 | // 6 | // Created by MJ Lee on 14-5-28. 7 | // Copyright (c) 2014年 小码哥. All rights reserved. 8 | // 9 | 10 | #import 11 | 12 | @interface UIScrollView (MJExtension) 13 | @property (assign, nonatomic) CGFloat mj_insetT; 14 | @property (assign, nonatomic) CGFloat mj_insetB; 15 | @property (assign, nonatomic) CGFloat mj_insetL; 16 | @property (assign, nonatomic) CGFloat mj_insetR; 17 | 18 | @property (assign, nonatomic) CGFloat mj_offsetX; 19 | @property (assign, nonatomic) CGFloat mj_offsetY; 20 | 21 | @property (assign, nonatomic) CGFloat mj_contentW; 22 | @property (assign, nonatomic) CGFloat mj_contentH; 23 | @end 24 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/UIScrollView+MJExtension.m: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: 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 3 | // UIScrollView+Extension.m 4 | // MJRefreshExample 5 | // 6 | // Created by MJ Lee on 14-5-28. 7 | // Copyright (c) 2014年 小码哥. All rights reserved. 8 | // 9 | 10 | #import "UIScrollView+MJExtension.h" 11 | #import 12 | 13 | @implementation UIScrollView (MJExtension) 14 | 15 | - (void)setMj_insetT:(CGFloat)mj_insetT 16 | { 17 | UIEdgeInsets inset = self.contentInset; 18 | inset.top = mj_insetT; 19 | self.contentInset = inset; 20 | } 21 | 22 | - (CGFloat)mj_insetT 23 | { 24 | return self.contentInset.top; 25 | } 26 | 27 | - (void)setMj_insetB:(CGFloat)mj_insetB 28 | { 29 | UIEdgeInsets inset = self.contentInset; 30 | inset.bottom = mj_insetB; 31 | self.contentInset = inset; 32 | } 33 | 34 | - (CGFloat)mj_insetB 35 | { 36 | return self.contentInset.bottom; 37 | } 38 | 39 | - (void)setMj_insetL:(CGFloat)mj_insetL 40 | { 41 | UIEdgeInsets inset = self.contentInset; 42 | inset.left = mj_insetL; 43 | self.contentInset = inset; 44 | } 45 | 46 | - (CGFloat)mj_insetL 47 | { 48 | return self.contentInset.left; 49 | } 50 | 51 | - (void)setMj_insetR:(CGFloat)mj_insetR 52 | { 53 | UIEdgeInsets inset = self.contentInset; 54 | inset.right = mj_insetR; 55 | self.contentInset = inset; 56 | } 57 | 58 | - (CGFloat)mj_insetR 59 | { 60 | return self.contentInset.right; 61 | } 62 | 63 | - (void)setMj_offsetX:(CGFloat)mj_offsetX 64 | { 65 | CGPoint offset = self.contentOffset; 66 | offset.x = mj_offsetX; 67 | self.contentOffset = offset; 68 | } 69 | 70 | - (CGFloat)mj_offsetX 71 | { 72 | return self.contentOffset.x; 73 | } 74 | 75 | - (void)setMj_offsetY:(CGFloat)mj_offsetY 76 | { 77 | CGPoint offset = self.contentOffset; 78 | offset.y = mj_offsetY; 79 | self.contentOffset = offset; 80 | } 81 | 82 | - (CGFloat)mj_offsetY 83 | { 84 | return self.contentOffset.y; 85 | } 86 | 87 | - (void)setMj_contentW:(CGFloat)mj_contentW 88 | { 89 | CGSize size = self.contentSize; 90 | size.width = mj_contentW; 91 | self.contentSize = size; 92 | } 93 | 94 | - (CGFloat)mj_contentW 95 | { 96 | return self.contentSize.width; 97 | } 98 | 99 | - (void)setMj_contentH:(CGFloat)mj_contentH 100 | { 101 | CGSize size = self.contentSize; 102 | size.height = mj_contentH; 103 | self.contentSize = size; 104 | } 105 | 106 | - (CGFloat)mj_contentH 107 | { 108 | return self.contentSize.height; 109 | } 110 | @end 111 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/UIScrollView+MJRefresh.h: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: 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 3 | // UIScrollView+MJRefresh.h 4 | // MJRefreshExample 5 | // 6 | // Created by MJ Lee on 15/3/4. 7 | // Copyright (c) 2015年 小码哥. All rights reserved. 8 | // 给ScrollView增加下拉刷新、上拉刷新的功能 9 | 10 | #import 11 | #import "MJRefreshConst.h" 12 | 13 | @class MJRefreshHeader, MJRefreshFooter; 14 | 15 | @interface UIScrollView (MJRefresh) 16 | /** 下拉刷新控件 */ 17 | @property (strong, nonatomic) MJRefreshHeader *mj_header; 18 | @property (strong, nonatomic) MJRefreshHeader *header MJRefreshDeprecated("使用mj_header"); 19 | /** 上拉刷新控件 */ 20 | @property (strong, nonatomic) MJRefreshFooter *mj_footer; 21 | @property (strong, nonatomic) MJRefreshFooter *footer MJRefreshDeprecated("使用mj_footer"); 22 | 23 | #pragma mark - other 24 | - (NSInteger)mj_totalDataCount; 25 | @property (copy, nonatomic) void (^mj_reloadDataBlock)(NSInteger totalDataCount); 26 | @end 27 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/UIScrollView+MJRefresh.m: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: 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 3 | // UIScrollView+MJRefresh.m 4 | // MJRefreshExample 5 | // 6 | // Created by MJ Lee on 15/3/4. 7 | // Copyright (c) 2015年 小码哥. All rights reserved. 8 | // 9 | 10 | #import "UIScrollView+MJRefresh.h" 11 | #import "MJRefreshHeader.h" 12 | #import "MJRefreshFooter.h" 13 | #import 14 | 15 | @implementation NSObject (MJRefresh) 16 | 17 | + (void)exchangeInstanceMethod1:(SEL)method1 method2:(SEL)method2 18 | { 19 | method_exchangeImplementations(class_getInstanceMethod(self, method1), class_getInstanceMethod(self, method2)); 20 | } 21 | 22 | + (void)exchangeClassMethod1:(SEL)method1 method2:(SEL)method2 23 | { 24 | method_exchangeImplementations(class_getClassMethod(self, method1), class_getClassMethod(self, method2)); 25 | } 26 | 27 | @end 28 | 29 | @implementation UIScrollView (MJRefresh) 30 | 31 | #pragma mark - header 32 | static const char MJRefreshHeaderKey = '\0'; 33 | - (void)setMj_header:(MJRefreshHeader *)mj_header 34 | { 35 | if (mj_header != self.mj_header) { 36 | // 删除旧的,添加新的 37 | [self.mj_header removeFromSuperview]; 38 | [self insertSubview:mj_header atIndex:0]; 39 | 40 | // 存储新的 41 | [self willChangeValueForKey:@"mj_header"]; // KVO 42 | objc_setAssociatedObject(self, &MJRefreshHeaderKey, 43 | mj_header, OBJC_ASSOCIATION_ASSIGN); 44 | [self didChangeValueForKey:@"mj_header"]; // KVO 45 | } 46 | } 47 | 48 | - (MJRefreshHeader *)mj_header 49 | { 50 | return objc_getAssociatedObject(self, &MJRefreshHeaderKey); 51 | } 52 | 53 | #pragma mark - footer 54 | static const char MJRefreshFooterKey = '\0'; 55 | - (void)setMj_footer:(MJRefreshFooter *)mj_footer 56 | { 57 | if (mj_footer != self.mj_footer) { 58 | // 删除旧的,添加新的 59 | [self.mj_footer removeFromSuperview]; 60 | [self insertSubview:mj_footer atIndex:0]; 61 | 62 | // 存储新的 63 | [self willChangeValueForKey:@"mj_footer"]; // KVO 64 | objc_setAssociatedObject(self, &MJRefreshFooterKey, 65 | mj_footer, OBJC_ASSOCIATION_ASSIGN); 66 | [self didChangeValueForKey:@"mj_footer"]; // KVO 67 | } 68 | } 69 | 70 | - (MJRefreshFooter *)mj_footer 71 | { 72 | return objc_getAssociatedObject(self, &MJRefreshFooterKey); 73 | } 74 | 75 | #pragma mark - 过期 76 | - (void)setFooter:(MJRefreshFooter *)footer 77 | { 78 | self.mj_footer = footer; 79 | } 80 | 81 | - (MJRefreshFooter *)footer 82 | { 83 | return self.mj_footer; 84 | } 85 | 86 | - (void)setHeader:(MJRefreshHeader *)header 87 | { 88 | self.mj_header = header; 89 | } 90 | 91 | - (MJRefreshHeader *)header 92 | { 93 | return self.mj_header; 94 | } 95 | 96 | #pragma mark - other 97 | - (NSInteger)mj_totalDataCount 98 | { 99 | NSInteger totalCount = 0; 100 | if ([self isKindOfClass:[UITableView class]]) { 101 | UITableView *tableView = (UITableView *)self; 102 | 103 | for (NSInteger section = 0; section 11 | 12 | @interface UIView (MJExtension) 13 | @property (assign, nonatomic) CGFloat mj_x; 14 | @property (assign, nonatomic) CGFloat mj_y; 15 | @property (assign, nonatomic) CGFloat mj_w; 16 | @property (assign, nonatomic) CGFloat mj_h; 17 | @property (assign, nonatomic) CGSize mj_size; 18 | @property (assign, nonatomic) CGPoint mj_origin; 19 | @end 20 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/MJRefresh/MJRefresh/UIView+MJExtension.m: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: 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 3 | // UIView+Extension.m 4 | // MJRefreshExample 5 | // 6 | // Created by MJ Lee on 14-5-28. 7 | // Copyright (c) 2014年 小码哥. All rights reserved. 8 | // 9 | 10 | #import "UIView+MJExtension.h" 11 | 12 | @implementation UIView (MJExtension) 13 | - (void)setMj_x:(CGFloat)mj_x 14 | { 15 | CGRect frame = self.frame; 16 | frame.origin.x = mj_x; 17 | self.frame = frame; 18 | } 19 | 20 | - (CGFloat)mj_x 21 | { 22 | return self.frame.origin.x; 23 | } 24 | 25 | - (void)setMj_y:(CGFloat)mj_y 26 | { 27 | CGRect frame = self.frame; 28 | frame.origin.y = mj_y; 29 | self.frame = frame; 30 | } 31 | 32 | - (CGFloat)mj_y 33 | { 34 | return self.frame.origin.y; 35 | } 36 | 37 | - (void)setMj_w:(CGFloat)mj_w 38 | { 39 | CGRect frame = self.frame; 40 | frame.size.width = mj_w; 41 | self.frame = frame; 42 | } 43 | 44 | - (CGFloat)mj_w 45 | { 46 | return self.frame.size.width; 47 | } 48 | 49 | - (void)setMj_h:(CGFloat)mj_h 50 | { 51 | CGRect frame = self.frame; 52 | frame.size.height = mj_h; 53 | self.frame = frame; 54 | } 55 | 56 | - (CGFloat)mj_h 57 | { 58 | return self.frame.size.height; 59 | } 60 | 61 | - (void)setMj_size:(CGSize)mj_size 62 | { 63 | CGRect frame = self.frame; 64 | frame.size = mj_size; 65 | self.frame = frame; 66 | } 67 | 68 | - (CGSize)mj_size 69 | { 70 | return self.frame.size; 71 | } 72 | 73 | - (void)setMj_origin:(CGPoint)mj_origin 74 | { 75 | CGRect frame = self.frame; 76 | frame.origin = mj_origin; 77 | self.frame = frame; 78 | } 79 | 80 | - (CGPoint)mj_origin 81 | { 82 | return self.frame.origin; 83 | } 84 | @end 85 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011-2012 Masonry Team - https://github.com/Masonry 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/MASCompositeConstraint.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASCompositeConstraint.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 21/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASConstraint.h" 10 | #import "MASUtilities.h" 11 | 12 | /** 13 | * A group of MASConstraint objects 14 | */ 15 | @interface MASCompositeConstraint : MASConstraint 16 | 17 | /** 18 | * Creates a composite with a predefined array of children 19 | * 20 | * @param children child MASConstraints 21 | * 22 | * @return a composite constraint 23 | */ 24 | - (id)initWithChildren:(NSArray *)children; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/MASCompositeConstraint.m: -------------------------------------------------------------------------------- 1 | // 2 | // MASCompositeConstraint.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 21/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASCompositeConstraint.h" 10 | #import "MASConstraint+Private.h" 11 | 12 | @interface MASCompositeConstraint () 13 | 14 | @property (nonatomic, strong) id mas_key; 15 | @property (nonatomic, strong) NSMutableArray *childConstraints; 16 | 17 | @end 18 | 19 | @implementation MASCompositeConstraint 20 | 21 | - (id)initWithChildren:(NSArray *)children { 22 | self = [super init]; 23 | if (!self) return nil; 24 | 25 | _childConstraints = [children mutableCopy]; 26 | for (MASConstraint *constraint in _childConstraints) { 27 | constraint.delegate = self; 28 | } 29 | 30 | return self; 31 | } 32 | 33 | #pragma mark - MASConstraintDelegate 34 | 35 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint { 36 | NSUInteger index = [self.childConstraints indexOfObject:constraint]; 37 | NSAssert(index != NSNotFound, @"Could not find constraint %@", constraint); 38 | [self.childConstraints replaceObjectAtIndex:index withObject:replacementConstraint]; 39 | } 40 | 41 | - (MASConstraint *)constraint:(MASConstraint __unused *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute { 42 | id strongDelegate = self.delegate; 43 | MASConstraint *newConstraint = [strongDelegate constraint:self addConstraintWithLayoutAttribute:layoutAttribute]; 44 | newConstraint.delegate = self; 45 | [self.childConstraints addObject:newConstraint]; 46 | return newConstraint; 47 | } 48 | 49 | #pragma mark - NSLayoutConstraint multiplier proxies 50 | 51 | - (MASConstraint * (^)(CGFloat))multipliedBy { 52 | return ^id(CGFloat multiplier) { 53 | for (MASConstraint *constraint in self.childConstraints) { 54 | constraint.multipliedBy(multiplier); 55 | } 56 | return self; 57 | }; 58 | } 59 | 60 | - (MASConstraint * (^)(CGFloat))dividedBy { 61 | return ^id(CGFloat divider) { 62 | for (MASConstraint *constraint in self.childConstraints) { 63 | constraint.dividedBy(divider); 64 | } 65 | return self; 66 | }; 67 | } 68 | 69 | #pragma mark - MASLayoutPriority proxy 70 | 71 | - (MASConstraint * (^)(MASLayoutPriority))priority { 72 | return ^id(MASLayoutPriority priority) { 73 | for (MASConstraint *constraint in self.childConstraints) { 74 | constraint.priority(priority); 75 | } 76 | return self; 77 | }; 78 | } 79 | 80 | #pragma mark - NSLayoutRelation proxy 81 | 82 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation { 83 | return ^id(id attr, NSLayoutRelation relation) { 84 | for (MASConstraint *constraint in self.childConstraints.copy) { 85 | constraint.equalToWithRelation(attr, relation); 86 | } 87 | return self; 88 | }; 89 | } 90 | 91 | #pragma mark - attribute chaining 92 | 93 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute { 94 | [self constraint:self addConstraintWithLayoutAttribute:layoutAttribute]; 95 | return self; 96 | } 97 | 98 | #pragma mark - Animator proxy 99 | 100 | #if TARGET_OS_MAC && !TARGET_OS_IPHONE 101 | 102 | - (MASConstraint *)animator { 103 | for (MASConstraint *constraint in self.childConstraints) { 104 | [constraint animator]; 105 | } 106 | return self; 107 | } 108 | 109 | #endif 110 | 111 | #pragma mark - debug helpers 112 | 113 | - (MASConstraint * (^)(id))key { 114 | return ^id(id key) { 115 | self.mas_key = key; 116 | int i = 0; 117 | for (MASConstraint *constraint in self.childConstraints) { 118 | constraint.key([NSString stringWithFormat:@"%@[%d]", key, i++]); 119 | } 120 | return self; 121 | }; 122 | } 123 | 124 | #pragma mark - NSLayoutConstraint constant setters 125 | 126 | - (void)setInsets:(MASEdgeInsets)insets { 127 | for (MASConstraint *constraint in self.childConstraints) { 128 | constraint.insets = insets; 129 | } 130 | } 131 | 132 | - (void)setOffset:(CGFloat)offset { 133 | for (MASConstraint *constraint in self.childConstraints) { 134 | constraint.offset = offset; 135 | } 136 | } 137 | 138 | - (void)setSizeOffset:(CGSize)sizeOffset { 139 | for (MASConstraint *constraint in self.childConstraints) { 140 | constraint.sizeOffset = sizeOffset; 141 | } 142 | } 143 | 144 | - (void)setCenterOffset:(CGPoint)centerOffset { 145 | for (MASConstraint *constraint in self.childConstraints) { 146 | constraint.centerOffset = centerOffset; 147 | } 148 | } 149 | 150 | #pragma mark - MASConstraint 151 | 152 | - (void)install { 153 | for (MASConstraint *constraint in self.childConstraints) { 154 | constraint.updateExisting = self.updateExisting; 155 | [constraint install]; 156 | } 157 | } 158 | 159 | - (void)uninstall { 160 | for (MASConstraint *constraint in self.childConstraints) { 161 | [constraint uninstall]; 162 | } 163 | } 164 | 165 | @end 166 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/MASConstraint+Private.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraint+Private.h 3 | // Masonry 4 | // 5 | // Created by Nick Tymchenko on 29/04/14. 6 | // Copyright (c) 2014 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASConstraint.h" 10 | 11 | @protocol MASConstraintDelegate; 12 | 13 | 14 | @interface MASConstraint () 15 | 16 | /** 17 | * Whether or not to check for an existing constraint instead of adding constraint 18 | */ 19 | @property (nonatomic, assign) BOOL updateExisting; 20 | 21 | /** 22 | * Usually MASConstraintMaker but could be a parent MASConstraint 23 | */ 24 | @property (nonatomic, weak) id delegate; 25 | 26 | /** 27 | * Based on a provided value type, is equal to calling: 28 | * NSNumber - setOffset: 29 | * NSValue with CGPoint - setPointOffset: 30 | * NSValue with CGSize - setSizeOffset: 31 | * NSValue with MASEdgeInsets - setInsets: 32 | */ 33 | - (void)setLayoutConstantWithValue:(NSValue *)value; 34 | 35 | @end 36 | 37 | 38 | @interface MASConstraint (Abstract) 39 | 40 | /** 41 | * Sets the constraint relation to given NSLayoutRelation 42 | * returns a block which accepts one of the following: 43 | * MASViewAttribute, UIView, NSValue, NSArray 44 | * see readme for more details. 45 | */ 46 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation; 47 | 48 | /** 49 | * Override to set a custom chaining behaviour 50 | */ 51 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute; 52 | 53 | @end 54 | 55 | 56 | @protocol MASConstraintDelegate 57 | 58 | /** 59 | * Notifies the delegate when the constraint needs to be replaced with another constraint. For example 60 | * A MASViewConstraint may turn into a MASCompositeConstraint when an array is passed to one of the equality blocks 61 | */ 62 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint; 63 | 64 | - (MASConstraint *)constraint:(MASConstraint *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute; 65 | 66 | @end -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/MASConstraint.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraint.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 22/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASUtilities.h" 10 | 11 | /** 12 | * Enables Constraints to be created with chainable syntax 13 | * Constraint can represent single NSLayoutConstraint (MASViewConstraint) 14 | * or a group of NSLayoutConstraints (MASComposisteConstraint) 15 | */ 16 | @interface MASConstraint : NSObject 17 | 18 | // Chaining Support 19 | 20 | /** 21 | * Modifies the NSLayoutConstraint constant, 22 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 23 | * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight 24 | */ 25 | - (MASConstraint * (^)(MASEdgeInsets insets))insets; 26 | 27 | /** 28 | * Modifies the NSLayoutConstraint constant, 29 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 30 | * NSLayoutAttributeWidth, NSLayoutAttributeHeight 31 | */ 32 | - (MASConstraint * (^)(CGSize offset))sizeOffset; 33 | 34 | /** 35 | * Modifies the NSLayoutConstraint constant, 36 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 37 | * NSLayoutAttributeCenterX, NSLayoutAttributeCenterY 38 | */ 39 | - (MASConstraint * (^)(CGPoint offset))centerOffset; 40 | 41 | /** 42 | * Modifies the NSLayoutConstraint constant 43 | */ 44 | - (MASConstraint * (^)(CGFloat offset))offset; 45 | 46 | /** 47 | * Modifies the NSLayoutConstraint constant based on a value type 48 | */ 49 | - (MASConstraint * (^)(NSValue *value))valueOffset; 50 | 51 | /** 52 | * Sets the NSLayoutConstraint multiplier property 53 | */ 54 | - (MASConstraint * (^)(CGFloat multiplier))multipliedBy; 55 | 56 | /** 57 | * Sets the NSLayoutConstraint multiplier to 1.0/dividedBy 58 | */ 59 | - (MASConstraint * (^)(CGFloat divider))dividedBy; 60 | 61 | /** 62 | * Sets the NSLayoutConstraint priority to a float or MASLayoutPriority 63 | */ 64 | - (MASConstraint * (^)(MASLayoutPriority priority))priority; 65 | 66 | /** 67 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityLow 68 | */ 69 | - (MASConstraint * (^)())priorityLow; 70 | 71 | /** 72 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityMedium 73 | */ 74 | - (MASConstraint * (^)())priorityMedium; 75 | 76 | /** 77 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityHigh 78 | */ 79 | - (MASConstraint * (^)())priorityHigh; 80 | 81 | /** 82 | * Sets the constraint relation to NSLayoutRelationEqual 83 | * returns a block which accepts one of the following: 84 | * MASViewAttribute, UIView, NSValue, NSArray 85 | * see readme for more details. 86 | */ 87 | - (MASConstraint * (^)(id attr))equalTo; 88 | 89 | /** 90 | * Sets the constraint relation to NSLayoutRelationGreaterThanOrEqual 91 | * returns a block which accepts one of the following: 92 | * MASViewAttribute, UIView, NSValue, NSArray 93 | * see readme for more details. 94 | */ 95 | - (MASConstraint * (^)(id attr))greaterThanOrEqualTo; 96 | 97 | /** 98 | * Sets the constraint relation to NSLayoutRelationLessThanOrEqual 99 | * returns a block which accepts one of the following: 100 | * MASViewAttribute, UIView, NSValue, NSArray 101 | * see readme for more details. 102 | */ 103 | - (MASConstraint * (^)(id attr))lessThanOrEqualTo; 104 | 105 | /** 106 | * Optional semantic property which has no effect but improves the readability of constraint 107 | */ 108 | - (MASConstraint *)with; 109 | 110 | /** 111 | * optional semantic property which has no effect but improves the readability of constraint 112 | */ 113 | - (MASConstraint *)and; 114 | 115 | /** 116 | * creates a new MASCompositeConstraint with the called attribute and reciever 117 | */ 118 | - (MASConstraint *)left; 119 | - (MASConstraint *)top; 120 | - (MASConstraint *)right; 121 | - (MASConstraint *)bottom; 122 | - (MASConstraint *)leading; 123 | - (MASConstraint *)trailing; 124 | - (MASConstraint *)width; 125 | - (MASConstraint *)height; 126 | - (MASConstraint *)centerX; 127 | - (MASConstraint *)centerY; 128 | - (MASConstraint *)baseline; 129 | 130 | /** 131 | * Sets the constraint debug name 132 | */ 133 | - (MASConstraint * (^)(id key))key; 134 | 135 | // NSLayoutConstraint constant Setters 136 | // for use outside of mas_updateConstraints/mas_makeConstraints blocks 137 | 138 | /** 139 | * Modifies the NSLayoutConstraint constant, 140 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 141 | * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight 142 | */ 143 | - (void)setInsets:(MASEdgeInsets)insets; 144 | 145 | /** 146 | * Modifies the NSLayoutConstraint constant, 147 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 148 | * NSLayoutAttributeWidth, NSLayoutAttributeHeight 149 | */ 150 | - (void)setSizeOffset:(CGSize)sizeOffset; 151 | 152 | /** 153 | * Modifies the NSLayoutConstraint constant, 154 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 155 | * NSLayoutAttributeCenterX, NSLayoutAttributeCenterY 156 | */ 157 | - (void)setCenterOffset:(CGPoint)centerOffset; 158 | 159 | /** 160 | * Modifies the NSLayoutConstraint constant 161 | */ 162 | - (void)setOffset:(CGFloat)offset; 163 | 164 | 165 | // NSLayoutConstraint Installation support 166 | 167 | #if TARGET_OS_MAC && !TARGET_OS_IPHONE 168 | /** 169 | * Whether or not to go through the animator proxy when modifying the constraint 170 | */ 171 | @property (nonatomic, copy, readonly) MASConstraint *animator; 172 | #endif 173 | 174 | /** 175 | * Creates a NSLayoutConstraint and adds it to the appropriate view. 176 | */ 177 | - (void)install; 178 | 179 | /** 180 | * Removes previously installed NSLayoutConstraint 181 | */ 182 | - (void)uninstall; 183 | 184 | @end 185 | 186 | 187 | /** 188 | * Convenience auto-boxing macros for MASConstraint methods. 189 | * 190 | * Defining MAS_SHORTHAND_GLOBALS will turn on auto-boxing for default syntax. 191 | * A potential drawback of this is that the unprefixed macros will appear in global scope. 192 | */ 193 | #define mas_equalTo(...) equalTo(MASBoxValue((__VA_ARGS__))) 194 | #define mas_greaterThanOrEqualTo(...) greaterThanOrEqualTo(MASBoxValue((__VA_ARGS__))) 195 | #define mas_lessThanOrEqualTo(...) lessThanOrEqualTo(MASBoxValue((__VA_ARGS__))) 196 | 197 | #define mas_offset(...) valueOffset(MASBoxValue((__VA_ARGS__))) 198 | 199 | 200 | #ifdef MAS_SHORTHAND_GLOBALS 201 | 202 | #define equalTo(...) mas_equalTo(__VA_ARGS__) 203 | #define greaterThanOrEqualTo(...) mas_greaterThanOrEqualTo(__VA_ARGS__) 204 | #define lessThanOrEqualTo(...) mas_lessThanOrEqualTo(__VA_ARGS__) 205 | 206 | #define offset(...) mas_offset(__VA_ARGS__) 207 | 208 | #endif 209 | 210 | 211 | @interface MASConstraint (AutoboxingSupport) 212 | 213 | /** 214 | * Aliases to corresponding relation methods (for shorthand macros) 215 | * Also needed to aid autocompletion 216 | */ 217 | - (MASConstraint * (^)(id attr))mas_equalTo; 218 | - (MASConstraint * (^)(id attr))mas_greaterThanOrEqualTo; 219 | - (MASConstraint * (^)(id attr))mas_lessThanOrEqualTo; 220 | 221 | /** 222 | * A dummy method to aid autocompletion 223 | */ 224 | - (MASConstraint * (^)(id offset))mas_offset; 225 | 226 | @end 227 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/MASConstraint.m: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraint.m 3 | // Masonry 4 | // 5 | // Created by Nick Tymchenko on 1/20/14. 6 | // 7 | 8 | #import "MASConstraint.h" 9 | #import "MASConstraint+Private.h" 10 | 11 | #define MASMethodNotImplemented() \ 12 | @throw [NSException exceptionWithName:NSInternalInconsistencyException \ 13 | reason:[NSString stringWithFormat:@"You must override %@ in a subclass.", NSStringFromSelector(_cmd)] \ 14 | userInfo:nil] 15 | 16 | @implementation MASConstraint 17 | 18 | #pragma mark - Init 19 | 20 | - (id)init { 21 | NSAssert(![self isMemberOfClass:[MASConstraint class]], @"MASConstraint is an abstract class, you should not instantiate it directly."); 22 | return [super init]; 23 | } 24 | 25 | #pragma mark - NSLayoutRelation proxies 26 | 27 | - (MASConstraint * (^)(id))equalTo { 28 | return ^id(id attribute) { 29 | return self.equalToWithRelation(attribute, NSLayoutRelationEqual); 30 | }; 31 | } 32 | 33 | - (MASConstraint * (^)(id))mas_equalTo { 34 | return ^id(id attribute) { 35 | return self.equalToWithRelation(attribute, NSLayoutRelationEqual); 36 | }; 37 | } 38 | 39 | - (MASConstraint * (^)(id))greaterThanOrEqualTo { 40 | return ^id(id attribute) { 41 | return self.equalToWithRelation(attribute, NSLayoutRelationGreaterThanOrEqual); 42 | }; 43 | } 44 | 45 | - (MASConstraint * (^)(id))mas_greaterThanOrEqualTo { 46 | return ^id(id attribute) { 47 | return self.equalToWithRelation(attribute, NSLayoutRelationGreaterThanOrEqual); 48 | }; 49 | } 50 | 51 | - (MASConstraint * (^)(id))lessThanOrEqualTo { 52 | return ^id(id attribute) { 53 | return self.equalToWithRelation(attribute, NSLayoutRelationLessThanOrEqual); 54 | }; 55 | } 56 | 57 | - (MASConstraint * (^)(id))mas_lessThanOrEqualTo { 58 | return ^id(id attribute) { 59 | return self.equalToWithRelation(attribute, NSLayoutRelationLessThanOrEqual); 60 | }; 61 | } 62 | 63 | #pragma mark - MASLayoutPriority proxies 64 | 65 | - (MASConstraint * (^)())priorityLow { 66 | return ^id{ 67 | self.priority(MASLayoutPriorityDefaultLow); 68 | return self; 69 | }; 70 | } 71 | 72 | - (MASConstraint * (^)())priorityMedium { 73 | return ^id{ 74 | self.priority(MASLayoutPriorityDefaultMedium); 75 | return self; 76 | }; 77 | } 78 | 79 | - (MASConstraint * (^)())priorityHigh { 80 | return ^id{ 81 | self.priority(MASLayoutPriorityDefaultHigh); 82 | return self; 83 | }; 84 | } 85 | 86 | #pragma mark - NSLayoutConstraint constant proxies 87 | 88 | - (MASConstraint * (^)(MASEdgeInsets))insets { 89 | return ^id(MASEdgeInsets insets){ 90 | self.insets = insets; 91 | return self; 92 | }; 93 | } 94 | 95 | - (MASConstraint * (^)(CGSize))sizeOffset { 96 | return ^id(CGSize offset) { 97 | self.sizeOffset = offset; 98 | return self; 99 | }; 100 | } 101 | 102 | - (MASConstraint * (^)(CGPoint))centerOffset { 103 | return ^id(CGPoint offset) { 104 | self.centerOffset = offset; 105 | return self; 106 | }; 107 | } 108 | 109 | - (MASConstraint * (^)(CGFloat))offset { 110 | return ^id(CGFloat offset){ 111 | self.offset = offset; 112 | return self; 113 | }; 114 | } 115 | 116 | - (MASConstraint * (^)(NSValue *value))valueOffset { 117 | return ^id(NSValue *offset) { 118 | NSAssert([offset isKindOfClass:NSValue.class], @"expected an NSValue offset, got: %@", offset); 119 | [self setLayoutConstantWithValue:offset]; 120 | return self; 121 | }; 122 | } 123 | 124 | - (MASConstraint * (^)(id offset))mas_offset { 125 | // Will never be called due to macro 126 | return nil; 127 | } 128 | 129 | #pragma mark - NSLayoutConstraint constant setter 130 | 131 | - (void)setLayoutConstantWithValue:(NSValue *)value { 132 | if ([value isKindOfClass:NSNumber.class]) { 133 | self.offset = [(NSNumber *)value doubleValue]; 134 | } else if (strcmp(value.objCType, @encode(CGPoint)) == 0) { 135 | CGPoint point; 136 | [value getValue:&point]; 137 | self.centerOffset = point; 138 | } else if (strcmp(value.objCType, @encode(CGSize)) == 0) { 139 | CGSize size; 140 | [value getValue:&size]; 141 | self.sizeOffset = size; 142 | } else if (strcmp(value.objCType, @encode(MASEdgeInsets)) == 0) { 143 | MASEdgeInsets insets; 144 | [value getValue:&insets]; 145 | self.insets = insets; 146 | } else { 147 | NSAssert(NO, @"attempting to set layout constant with unsupported value: %@", value); 148 | } 149 | } 150 | 151 | #pragma mark - Semantic properties 152 | 153 | - (MASConstraint *)with { 154 | return self; 155 | } 156 | 157 | - (MASConstraint *)and { 158 | return self; 159 | } 160 | 161 | #pragma mark - Chaining 162 | 163 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute __unused)layoutAttribute { 164 | MASMethodNotImplemented(); 165 | } 166 | 167 | - (MASConstraint *)left { 168 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeft]; 169 | } 170 | 171 | - (MASConstraint *)top { 172 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTop]; 173 | } 174 | 175 | - (MASConstraint *)right { 176 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRight]; 177 | } 178 | 179 | - (MASConstraint *)bottom { 180 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottom]; 181 | } 182 | 183 | - (MASConstraint *)leading { 184 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeading]; 185 | } 186 | 187 | - (MASConstraint *)trailing { 188 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailing]; 189 | } 190 | 191 | - (MASConstraint *)width { 192 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeWidth]; 193 | } 194 | 195 | - (MASConstraint *)height { 196 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeHeight]; 197 | } 198 | 199 | - (MASConstraint *)centerX { 200 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterX]; 201 | } 202 | 203 | - (MASConstraint *)centerY { 204 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterY]; 205 | } 206 | 207 | - (MASConstraint *)baseline { 208 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline]; 209 | } 210 | 211 | #pragma mark - Abstract 212 | 213 | - (MASConstraint * (^)(CGFloat multiplier))multipliedBy { MASMethodNotImplemented(); } 214 | 215 | - (MASConstraint * (^)(CGFloat divider))dividedBy { MASMethodNotImplemented(); } 216 | 217 | - (MASConstraint * (^)(MASLayoutPriority priority))priority { MASMethodNotImplemented(); } 218 | 219 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation { MASMethodNotImplemented(); } 220 | 221 | - (MASConstraint * (^)(id key))key { MASMethodNotImplemented(); } 222 | 223 | - (void)setInsets:(MASEdgeInsets __unused)insets { MASMethodNotImplemented(); } 224 | 225 | - (void)setSizeOffset:(CGSize __unused)sizeOffset { MASMethodNotImplemented(); } 226 | 227 | - (void)setCenterOffset:(CGPoint __unused)centerOffset { MASMethodNotImplemented(); } 228 | 229 | - (void)setOffset:(CGFloat __unused)offset { MASMethodNotImplemented(); } 230 | 231 | #if TARGET_OS_MAC && !TARGET_OS_IPHONE 232 | 233 | - (MASConstraint *)animator { MASMethodNotImplemented(); } 234 | 235 | #endif 236 | 237 | - (void)install { MASMethodNotImplemented(); } 238 | 239 | - (void)uninstall { MASMethodNotImplemented(); } 240 | 241 | @end 242 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/MASConstraintMaker.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraintBuilder.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASConstraint.h" 10 | #import "MASUtilities.h" 11 | 12 | typedef NS_OPTIONS(NSInteger, MASAttribute) { 13 | MASAttributeLeft = 1 << NSLayoutAttributeLeft, 14 | MASAttributeRight = 1 << NSLayoutAttributeRight, 15 | MASAttributeTop = 1 << NSLayoutAttributeTop, 16 | MASAttributeBottom = 1 << NSLayoutAttributeBottom, 17 | MASAttributeLeading = 1 << NSLayoutAttributeLeading, 18 | MASAttributeTrailing = 1 << NSLayoutAttributeTrailing, 19 | MASAttributeWidth = 1 << NSLayoutAttributeWidth, 20 | MASAttributeHeight = 1 << NSLayoutAttributeHeight, 21 | MASAttributeCenterX = 1 << NSLayoutAttributeCenterX, 22 | MASAttributeCenterY = 1 << NSLayoutAttributeCenterY, 23 | MASAttributeBaseline = 1 << NSLayoutAttributeBaseline, 24 | }; 25 | 26 | /** 27 | * Provides factory methods for creating MASConstraints. 28 | * Constraints are collected until they are ready to be installed 29 | * 30 | */ 31 | @interface MASConstraintMaker : NSObject 32 | 33 | /** 34 | * The following properties return a new MASViewConstraint 35 | * with the first item set to the makers associated view and the appropriate MASViewAttribute 36 | */ 37 | @property (nonatomic, strong, readonly) MASConstraint *left; 38 | @property (nonatomic, strong, readonly) MASConstraint *top; 39 | @property (nonatomic, strong, readonly) MASConstraint *right; 40 | @property (nonatomic, strong, readonly) MASConstraint *bottom; 41 | @property (nonatomic, strong, readonly) MASConstraint *leading; 42 | @property (nonatomic, strong, readonly) MASConstraint *trailing; 43 | @property (nonatomic, strong, readonly) MASConstraint *width; 44 | @property (nonatomic, strong, readonly) MASConstraint *height; 45 | @property (nonatomic, strong, readonly) MASConstraint *centerX; 46 | @property (nonatomic, strong, readonly) MASConstraint *centerY; 47 | @property (nonatomic, strong, readonly) MASConstraint *baseline; 48 | 49 | /** 50 | * Returns a block which creates a new MASCompositeConstraint with the first item set 51 | * to the makers associated view and children corresponding to the set bits in the 52 | * MASAttribute parameter. Combine multiple attributes via binary-or. 53 | */ 54 | @property (nonatomic, strong, readonly) MASConstraint *(^attributes)(MASAttribute attrs); 55 | 56 | /** 57 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeEdges 58 | * which generates the appropriate MASViewConstraint children (top, left, bottom, right) 59 | * with the first item set to the makers associated view 60 | */ 61 | @property (nonatomic, strong, readonly) MASConstraint *edges; 62 | 63 | /** 64 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeSize 65 | * which generates the appropriate MASViewConstraint children (width, height) 66 | * with the first item set to the makers associated view 67 | */ 68 | @property (nonatomic, strong, readonly) MASConstraint *size; 69 | 70 | /** 71 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeCenter 72 | * which generates the appropriate MASViewConstraint children (centerX, centerY) 73 | * with the first item set to the makers associated view 74 | */ 75 | @property (nonatomic, strong, readonly) MASConstraint *center; 76 | 77 | /** 78 | * Whether or not to check for an existing constraint instead of adding constraint 79 | */ 80 | @property (nonatomic, assign) BOOL updateExisting; 81 | 82 | /** 83 | * Whether or not to remove existing constraints prior to installing 84 | */ 85 | @property (nonatomic, assign) BOOL removeExisting; 86 | 87 | /** 88 | * initialises the maker with a default view 89 | * 90 | * @param view any MASConstrait are created with this view as the first item 91 | * 92 | * @return a new MASConstraintMaker 93 | */ 94 | - (id)initWithView:(MAS_VIEW *)view; 95 | 96 | /** 97 | * Calls install method on any MASConstraints which have been created by this maker 98 | * 99 | * @return an array of all the installed MASConstraints 100 | */ 101 | - (NSArray *)install; 102 | 103 | - (MASConstraint * (^)(dispatch_block_t))group; 104 | 105 | @end 106 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/MASConstraintMaker.m: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraintBuilder.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASConstraintMaker.h" 10 | #import "MASViewConstraint.h" 11 | #import "MASCompositeConstraint.h" 12 | #import "MASConstraint+Private.h" 13 | #import "MASViewAttribute.h" 14 | #import "View+MASAdditions.h" 15 | 16 | @interface MASConstraintMaker () 17 | 18 | @property (nonatomic, weak) MAS_VIEW *view; 19 | @property (nonatomic, strong) NSMutableArray *constraints; 20 | 21 | @end 22 | 23 | @implementation MASConstraintMaker 24 | 25 | - (id)initWithView:(MAS_VIEW *)view { 26 | self = [super init]; 27 | if (!self) return nil; 28 | 29 | self.view = view; 30 | self.constraints = NSMutableArray.new; 31 | 32 | return self; 33 | } 34 | 35 | - (NSArray *)install { 36 | if (self.removeExisting) { 37 | NSArray *installedConstraints = [MASViewConstraint installedConstraintsForView:self.view]; 38 | for (MASConstraint *constraint in installedConstraints) { 39 | [constraint uninstall]; 40 | } 41 | } 42 | NSArray *constraints = self.constraints.copy; 43 | for (MASConstraint *constraint in constraints) { 44 | constraint.updateExisting = self.updateExisting; 45 | [constraint install]; 46 | } 47 | [self.constraints removeAllObjects]; 48 | return constraints; 49 | } 50 | 51 | #pragma mark - MASConstraintDelegate 52 | 53 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint { 54 | NSUInteger index = [self.constraints indexOfObject:constraint]; 55 | NSAssert(index != NSNotFound, @"Could not find constraint %@", constraint); 56 | [self.constraints replaceObjectAtIndex:index withObject:replacementConstraint]; 57 | } 58 | 59 | - (MASConstraint *)constraint:(MASConstraint *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute { 60 | MASViewAttribute *viewAttribute = [[MASViewAttribute alloc] initWithView:self.view layoutAttribute:layoutAttribute]; 61 | MASViewConstraint *newConstraint = [[MASViewConstraint alloc] initWithFirstViewAttribute:viewAttribute]; 62 | if ([constraint isKindOfClass:MASViewConstraint.class]) { 63 | //replace with composite constraint 64 | NSArray *children = @[constraint, newConstraint]; 65 | MASCompositeConstraint *compositeConstraint = [[MASCompositeConstraint alloc] initWithChildren:children]; 66 | compositeConstraint.delegate = self; 67 | [self constraint:constraint shouldBeReplacedWithConstraint:compositeConstraint]; 68 | return compositeConstraint; 69 | } 70 | if (!constraint) { 71 | newConstraint.delegate = self; 72 | [self.constraints addObject:newConstraint]; 73 | } 74 | return newConstraint; 75 | } 76 | 77 | - (MASConstraint *)addConstraintWithAttributes:(MASAttribute)attrs { 78 | MASAttribute anyAttribute = MASAttributeLeft | MASAttributeRight | MASAttributeTop | MASAttributeBottom | MASAttributeLeading | MASAttributeTrailing | MASAttributeWidth | MASAttributeHeight | MASAttributeCenterX | MASAttributeCenterY | MASAttributeBaseline; 79 | 80 | NSAssert((attrs & anyAttribute) != 0, @"You didn't pass any attribute to make.attributes(...)"); 81 | 82 | NSMutableArray *attributes = [NSMutableArray array]; 83 | 84 | if (attrs & MASAttributeLeft) [attributes addObject:self.view.mas_left]; 85 | if (attrs & MASAttributeRight) [attributes addObject:self.view.mas_right]; 86 | if (attrs & MASAttributeTop) [attributes addObject:self.view.mas_top]; 87 | if (attrs & MASAttributeBottom) [attributes addObject:self.view.mas_bottom]; 88 | if (attrs & MASAttributeLeading) [attributes addObject:self.view.mas_leading]; 89 | if (attrs & MASAttributeTrailing) [attributes addObject:self.view.mas_trailing]; 90 | if (attrs & MASAttributeWidth) [attributes addObject:self.view.mas_width]; 91 | if (attrs & MASAttributeHeight) [attributes addObject:self.view.mas_height]; 92 | if (attrs & MASAttributeCenterX) [attributes addObject:self.view.mas_centerX]; 93 | if (attrs & MASAttributeCenterY) [attributes addObject:self.view.mas_centerY]; 94 | if (attrs & MASAttributeBaseline) [attributes addObject:self.view.mas_baseline]; 95 | 96 | NSMutableArray *children = [NSMutableArray arrayWithCapacity:attributes.count]; 97 | 98 | for (MASViewAttribute *a in attributes) { 99 | [children addObject:[[MASViewConstraint alloc] initWithFirstViewAttribute:a]]; 100 | } 101 | 102 | MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithChildren:children]; 103 | constraint.delegate = self; 104 | [self.constraints addObject:constraint]; 105 | return constraint; 106 | } 107 | 108 | #pragma mark - standard Attributes 109 | 110 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute { 111 | return [self constraint:nil addConstraintWithLayoutAttribute:layoutAttribute]; 112 | } 113 | 114 | - (MASConstraint *)left { 115 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeft]; 116 | } 117 | 118 | - (MASConstraint *)top { 119 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTop]; 120 | } 121 | 122 | - (MASConstraint *)right { 123 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRight]; 124 | } 125 | 126 | - (MASConstraint *)bottom { 127 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottom]; 128 | } 129 | 130 | - (MASConstraint *)leading { 131 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeading]; 132 | } 133 | 134 | - (MASConstraint *)trailing { 135 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailing]; 136 | } 137 | 138 | - (MASConstraint *)width { 139 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeWidth]; 140 | } 141 | 142 | - (MASConstraint *)height { 143 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeHeight]; 144 | } 145 | 146 | - (MASConstraint *)centerX { 147 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterX]; 148 | } 149 | 150 | - (MASConstraint *)centerY { 151 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterY]; 152 | } 153 | 154 | - (MASConstraint *)baseline { 155 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline]; 156 | } 157 | 158 | - (MASConstraint *(^)(MASAttribute))attributes { 159 | return ^(MASAttribute attrs){ 160 | return [self addConstraintWithAttributes:attrs]; 161 | }; 162 | } 163 | 164 | 165 | #pragma mark - composite Attributes 166 | 167 | - (MASConstraint *)edges { 168 | return [self addConstraintWithAttributes:MASAttributeTop | MASAttributeLeft | MASAttributeRight | MASAttributeBottom]; 169 | } 170 | 171 | - (MASConstraint *)size { 172 | return [self addConstraintWithAttributes:MASAttributeWidth | MASAttributeHeight]; 173 | } 174 | 175 | - (MASConstraint *)center { 176 | return [self addConstraintWithAttributes:MASAttributeCenterX | MASAttributeCenterY]; 177 | } 178 | 179 | #pragma mark - grouping 180 | 181 | - (MASConstraint *(^)(dispatch_block_t group))group { 182 | return ^id(dispatch_block_t group) { 183 | NSInteger previousCount = self.constraints.count; 184 | group(); 185 | 186 | NSArray *children = [self.constraints subarrayWithRange:NSMakeRange(previousCount, self.constraints.count - previousCount)]; 187 | MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithChildren:children]; 188 | constraint.delegate = self; 189 | return constraint; 190 | }; 191 | } 192 | 193 | @end 194 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/MASLayoutConstraint.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASLayoutConstraint.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 3/08/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "MASUtilities.h" 10 | 11 | /** 12 | * When you are debugging or printing the constraints attached to a view this subclass 13 | * makes it easier to identify which constraints have been created via Masonry 14 | */ 15 | @interface MASLayoutConstraint : NSLayoutConstraint 16 | 17 | /** 18 | * a key to associate with this constraint 19 | */ 20 | @property (nonatomic, strong) id mas_key; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/MASLayoutConstraint.m: -------------------------------------------------------------------------------- 1 | // 2 | // MASLayoutConstraint.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 3/08/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "MASLayoutConstraint.h" 10 | 11 | @implementation MASLayoutConstraint 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/MASUtilities.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASUtilities.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 19/08/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #if TARGET_OS_IPHONE 12 | 13 | #import 14 | #define MAS_VIEW UIView 15 | #define MASEdgeInsets UIEdgeInsets 16 | 17 | typedef UILayoutPriority MASLayoutPriority; 18 | static const MASLayoutPriority MASLayoutPriorityRequired = UILayoutPriorityRequired; 19 | static const MASLayoutPriority MASLayoutPriorityDefaultHigh = UILayoutPriorityDefaultHigh; 20 | static const MASLayoutPriority MASLayoutPriorityDefaultMedium = 500; 21 | static const MASLayoutPriority MASLayoutPriorityDefaultLow = UILayoutPriorityDefaultLow; 22 | static const MASLayoutPriority MASLayoutPriorityFittingSizeLevel = UILayoutPriorityFittingSizeLevel; 23 | 24 | #elif TARGET_OS_MAC 25 | 26 | #import 27 | #define MAS_VIEW NSView 28 | #define MASEdgeInsets NSEdgeInsets 29 | 30 | typedef NSLayoutPriority MASLayoutPriority; 31 | static const MASLayoutPriority MASLayoutPriorityRequired = NSLayoutPriorityRequired; 32 | static const MASLayoutPriority MASLayoutPriorityDefaultHigh = NSLayoutPriorityDefaultHigh; 33 | static const MASLayoutPriority MASLayoutPriorityDragThatCanResizeWindow = NSLayoutPriorityDragThatCanResizeWindow; 34 | static const MASLayoutPriority MASLayoutPriorityDefaultMedium = 501; 35 | static const MASLayoutPriority MASLayoutPriorityWindowSizeStayPut = NSLayoutPriorityWindowSizeStayPut; 36 | static const MASLayoutPriority MASLayoutPriorityDragThatCannotResizeWindow = NSLayoutPriorityDragThatCannotResizeWindow; 37 | static const MASLayoutPriority MASLayoutPriorityDefaultLow = NSLayoutPriorityDefaultLow; 38 | static const MASLayoutPriority MASLayoutPriorityFittingSizeCompression = NSLayoutPriorityFittingSizeCompression; 39 | 40 | #endif 41 | 42 | /** 43 | * Allows you to attach keys to objects matching the variable names passed. 44 | * 45 | * view1.mas_key = @"view1", view2.mas_key = @"view2"; 46 | * 47 | * is equivalent to: 48 | * 49 | * MASAttachKeys(view1, view2); 50 | */ 51 | #define MASAttachKeys(...) \ 52 | NSDictionary *keyPairs = NSDictionaryOfVariableBindings(__VA_ARGS__); \ 53 | for (id key in keyPairs.allKeys) { \ 54 | id obj = keyPairs[key]; \ 55 | NSAssert([obj respondsToSelector:@selector(setMas_key:)], \ 56 | @"Cannot attach mas_key to %@", obj); \ 57 | [obj setMas_key:key]; \ 58 | } 59 | 60 | /** 61 | * Used to create object hashes 62 | * Based on http://www.mikeash.com/pyblog/friday-qa-2010-06-18-implementing-equality-and-hashing.html 63 | */ 64 | #define MAS_NSUINT_BIT (CHAR_BIT * sizeof(NSUInteger)) 65 | #define MAS_NSUINTROTATE(val, howmuch) ((((NSUInteger)val) << howmuch) | (((NSUInteger)val) >> (MAS_NSUINT_BIT - howmuch))) 66 | 67 | /** 68 | * Given a scalar or struct value, wraps it in NSValue 69 | * Based on EXPObjectify: https://github.com/specta/expecta 70 | */ 71 | static inline id _MASBoxValue(const char *type, ...) { 72 | va_list v; 73 | va_start(v, type); 74 | id obj = nil; 75 | if (strcmp(type, @encode(id)) == 0) { 76 | id actual = va_arg(v, id); 77 | obj = actual; 78 | } else if (strcmp(type, @encode(CGPoint)) == 0) { 79 | CGPoint actual = (CGPoint)va_arg(v, CGPoint); 80 | obj = [NSValue value:&actual withObjCType:type]; 81 | } else if (strcmp(type, @encode(CGSize)) == 0) { 82 | CGSize actual = (CGSize)va_arg(v, CGSize); 83 | obj = [NSValue value:&actual withObjCType:type]; 84 | } else if (strcmp(type, @encode(MASEdgeInsets)) == 0) { 85 | MASEdgeInsets actual = (MASEdgeInsets)va_arg(v, MASEdgeInsets); 86 | obj = [NSValue value:&actual withObjCType:type]; 87 | } else if (strcmp(type, @encode(double)) == 0) { 88 | double actual = (double)va_arg(v, double); 89 | obj = [NSNumber numberWithDouble:actual]; 90 | } else if (strcmp(type, @encode(float)) == 0) { 91 | float actual = (float)va_arg(v, double); 92 | obj = [NSNumber numberWithFloat:actual]; 93 | } else if (strcmp(type, @encode(int)) == 0) { 94 | int actual = (int)va_arg(v, int); 95 | obj = [NSNumber numberWithInt:actual]; 96 | } else if (strcmp(type, @encode(long)) == 0) { 97 | long actual = (long)va_arg(v, long); 98 | obj = [NSNumber numberWithLong:actual]; 99 | } else if (strcmp(type, @encode(long long)) == 0) { 100 | long long actual = (long long)va_arg(v, long long); 101 | obj = [NSNumber numberWithLongLong:actual]; 102 | } else if (strcmp(type, @encode(short)) == 0) { 103 | short actual = (short)va_arg(v, int); 104 | obj = [NSNumber numberWithShort:actual]; 105 | } else if (strcmp(type, @encode(char)) == 0) { 106 | char actual = (char)va_arg(v, int); 107 | obj = [NSNumber numberWithChar:actual]; 108 | } else if (strcmp(type, @encode(bool)) == 0) { 109 | bool actual = (bool)va_arg(v, int); 110 | obj = [NSNumber numberWithBool:actual]; 111 | } else if (strcmp(type, @encode(unsigned char)) == 0) { 112 | unsigned char actual = (unsigned char)va_arg(v, unsigned int); 113 | obj = [NSNumber numberWithUnsignedChar:actual]; 114 | } else if (strcmp(type, @encode(unsigned int)) == 0) { 115 | unsigned int actual = (unsigned int)va_arg(v, unsigned int); 116 | obj = [NSNumber numberWithUnsignedInt:actual]; 117 | } else if (strcmp(type, @encode(unsigned long)) == 0) { 118 | unsigned long actual = (unsigned long)va_arg(v, unsigned long); 119 | obj = [NSNumber numberWithUnsignedLong:actual]; 120 | } else if (strcmp(type, @encode(unsigned long long)) == 0) { 121 | unsigned long long actual = (unsigned long long)va_arg(v, unsigned long long); 122 | obj = [NSNumber numberWithUnsignedLongLong:actual]; 123 | } else if (strcmp(type, @encode(unsigned short)) == 0) { 124 | unsigned short actual = (unsigned short)va_arg(v, unsigned int); 125 | obj = [NSNumber numberWithUnsignedShort:actual]; 126 | } 127 | va_end(v); 128 | return obj; 129 | } 130 | 131 | #define MASBoxValue(value) _MASBoxValue(@encode(__typeof__((value))), (value)) 132 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/MASViewAttribute.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASAttribute.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 21/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASUtilities.h" 10 | 11 | /** 12 | * An immutable tuple which stores the view and the related NSLayoutAttribute. 13 | * Describes part of either the left or right hand side of a constraint equation 14 | */ 15 | @interface MASViewAttribute : NSObject 16 | 17 | /** 18 | * The view which the reciever relates to 19 | */ 20 | @property (nonatomic, weak, readonly) MAS_VIEW *view; 21 | 22 | /** 23 | * The attribute which the reciever relates to 24 | */ 25 | @property (nonatomic, assign, readonly) NSLayoutAttribute layoutAttribute; 26 | 27 | /** 28 | * The designated initializer. 29 | */ 30 | - (id)initWithView:(MAS_VIEW *)view layoutAttribute:(NSLayoutAttribute)layoutAttribute; 31 | 32 | /** 33 | * Determine whether the layoutAttribute is a size attribute 34 | * 35 | * @return YES if layoutAttribute is equal to NSLayoutAttributeWidth or NSLayoutAttributeHeight 36 | */ 37 | - (BOOL)isSizeAttribute; 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/MASViewAttribute.m: -------------------------------------------------------------------------------- 1 | // 2 | // MASAttribute.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 21/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASViewAttribute.h" 10 | 11 | @implementation MASViewAttribute 12 | 13 | - (id)initWithView:(MAS_VIEW *)view layoutAttribute:(NSLayoutAttribute)layoutAttribute { 14 | self = [super init]; 15 | if (!self) return nil; 16 | 17 | _view = view; 18 | _layoutAttribute = layoutAttribute; 19 | 20 | return self; 21 | } 22 | 23 | - (BOOL)isSizeAttribute { 24 | return self.layoutAttribute == NSLayoutAttributeWidth 25 | || self.layoutAttribute == NSLayoutAttributeHeight; 26 | } 27 | 28 | - (BOOL)isEqual:(MASViewAttribute *)viewAttribute { 29 | if ([viewAttribute isKindOfClass:self.class]) { 30 | return self.view == viewAttribute.view 31 | && self.layoutAttribute == viewAttribute.layoutAttribute; 32 | } 33 | return [super isEqual:viewAttribute]; 34 | } 35 | 36 | - (NSUInteger)hash { 37 | return MAS_NSUINTROTATE([self.view hash], MAS_NSUINT_BIT / 2) ^ self.layoutAttribute; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/MASViewConstraint.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraint.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASViewAttribute.h" 10 | #import "MASConstraint.h" 11 | #import "MASLayoutConstraint.h" 12 | #import "MASUtilities.h" 13 | 14 | /** 15 | * A single constraint. 16 | * Contains the attributes neccessary for creating a NSLayoutConstraint and adding it to the appropriate view 17 | */ 18 | @interface MASViewConstraint : MASConstraint 19 | 20 | /** 21 | * First item/view and first attribute of the NSLayoutConstraint 22 | */ 23 | @property (nonatomic, strong, readonly) MASViewAttribute *firstViewAttribute; 24 | 25 | /** 26 | * Second item/view and second attribute of the NSLayoutConstraint 27 | */ 28 | @property (nonatomic, strong, readonly) MASViewAttribute *secondViewAttribute; 29 | 30 | /** 31 | * initialises the MASViewConstraint with the first part of the equation 32 | * 33 | * @param firstViewAttribute view.mas_left, view.mas_width etc. 34 | * 35 | * @return a new view constraint 36 | */ 37 | - (id)initWithFirstViewAttribute:(MASViewAttribute *)firstViewAttribute; 38 | 39 | /** 40 | * Returns all MASViewConstraints installed with this view as a first item. 41 | * 42 | * @param view A view to retrieve constraints for. 43 | * 44 | * @return An array of MASViewConstraints. 45 | */ 46 | + (NSArray *)installedConstraintsForView:(MAS_VIEW *)view; 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/Masonry.h: -------------------------------------------------------------------------------- 1 | // 2 | // Masonry.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASUtilities.h" 10 | #import "View+MASAdditions.h" 11 | #import "View+MASShorthandAdditions.h" 12 | #import "NSArray+MASAdditions.h" 13 | #import "NSArray+MASShorthandAdditions.h" 14 | #import "MASConstraint.h" 15 | #import "MASCompositeConstraint.h" 16 | #import "MASViewAttribute.h" 17 | #import "MASViewConstraint.h" 18 | #import "MASConstraintMaker.h" 19 | #import "MASLayoutConstraint.h" 20 | #import "NSLayoutConstraint+MASDebugAdditions.h" 21 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/NSArray+MASAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+MASAdditions.h 3 | // 4 | // 5 | // Created by Daniel Hammond on 11/26/13. 6 | // 7 | // 8 | 9 | #import "MASUtilities.h" 10 | #import "MASConstraintMaker.h" 11 | #import "MASViewAttribute.h" 12 | 13 | @interface NSArray (MASAdditions) 14 | 15 | /** 16 | * Creates a MASConstraintMaker with each view in the callee. 17 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing on each view 18 | * 19 | * @param block scope within which you can build up the constraints which you wish to apply to each view. 20 | * 21 | * @return Array of created MASConstraints 22 | */ 23 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block; 24 | 25 | /** 26 | * Creates a MASConstraintMaker with each view in the callee. 27 | * Any constraints defined are added to each view or the appropriate superview once the block has finished executing on each view. 28 | * If an existing constraint exists then it will be updated instead. 29 | * 30 | * @param block scope within which you can build up the constraints which you wish to apply to each view. 31 | * 32 | * @return Array of created/updated MASConstraints 33 | */ 34 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block; 35 | 36 | /** 37 | * Creates a MASConstraintMaker with each view in the callee. 38 | * Any constraints defined are added to each view or the appropriate superview once the block has finished executing on each view. 39 | * All constraints previously installed for the views will be removed. 40 | * 41 | * @param block scope within which you can build up the constraints which you wish to apply to each view. 42 | * 43 | * @return Array of created/updated MASConstraints 44 | */ 45 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/NSArray+MASAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+MASAdditions.m 3 | // 4 | // 5 | // Created by Daniel Hammond on 11/26/13. 6 | // 7 | // 8 | 9 | #import "NSArray+MASAdditions.h" 10 | #import "View+MASAdditions.h" 11 | 12 | @implementation NSArray (MASAdditions) 13 | 14 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block { 15 | NSMutableArray *constraints = [NSMutableArray array]; 16 | for (MAS_VIEW *view in self) { 17 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views"); 18 | [constraints addObjectsFromArray:[view mas_makeConstraints:block]]; 19 | } 20 | return constraints; 21 | } 22 | 23 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block { 24 | NSMutableArray *constraints = [NSMutableArray array]; 25 | for (MAS_VIEW *view in self) { 26 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views"); 27 | [constraints addObjectsFromArray:[view mas_updateConstraints:block]]; 28 | } 29 | return constraints; 30 | } 31 | 32 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block { 33 | NSMutableArray *constraints = [NSMutableArray array]; 34 | for (MAS_VIEW *view in self) { 35 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views"); 36 | [constraints addObjectsFromArray:[view mas_remakeConstraints:block]]; 37 | } 38 | return constraints; 39 | } 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/NSArray+MASShorthandAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+MASShorthandAdditions.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 22/07/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "NSArray+MASAdditions.h" 10 | 11 | #ifdef MAS_SHORTHAND 12 | 13 | /** 14 | * Shorthand array additions without the 'mas_' prefixes, 15 | * only enabled if MAS_SHORTHAND is defined 16 | */ 17 | @interface NSArray (MASShorthandAdditions) 18 | 19 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block; 20 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block; 21 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block; 22 | 23 | @end 24 | 25 | @implementation NSArray (MASShorthandAdditions) 26 | 27 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *))block { 28 | return [self mas_makeConstraints:block]; 29 | } 30 | 31 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *))block { 32 | return [self mas_updateConstraints:block]; 33 | } 34 | 35 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *))block { 36 | return [self mas_remakeConstraints:block]; 37 | } 38 | 39 | @end 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/NSLayoutConstraint+MASDebugAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSLayoutConstraint+MASDebugAdditions.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 3/08/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "MASUtilities.h" 10 | 11 | /** 12 | * makes debug and log output of NSLayoutConstraints more readable 13 | */ 14 | @interface NSLayoutConstraint (MASDebugAdditions) 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/NSLayoutConstraint+MASDebugAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSLayoutConstraint+MASDebugAdditions.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 3/08/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "NSLayoutConstraint+MASDebugAdditions.h" 10 | #import "MASConstraint.h" 11 | #import "MASLayoutConstraint.h" 12 | 13 | @implementation NSLayoutConstraint (MASDebugAdditions) 14 | 15 | #pragma mark - description maps 16 | 17 | + (NSDictionary *)layoutRelationDescriptionsByValue { 18 | static dispatch_once_t once; 19 | static NSDictionary *descriptionMap; 20 | dispatch_once(&once, ^{ 21 | descriptionMap = @{ 22 | @(NSLayoutRelationEqual) : @"==", 23 | @(NSLayoutRelationGreaterThanOrEqual) : @">=", 24 | @(NSLayoutRelationLessThanOrEqual) : @"<=", 25 | }; 26 | }); 27 | return descriptionMap; 28 | } 29 | 30 | + (NSDictionary *)layoutAttributeDescriptionsByValue { 31 | static dispatch_once_t once; 32 | static NSDictionary *descriptionMap; 33 | dispatch_once(&once, ^{ 34 | descriptionMap = @{ 35 | @(NSLayoutAttributeTop) : @"top", 36 | @(NSLayoutAttributeLeft) : @"left", 37 | @(NSLayoutAttributeBottom) : @"bottom", 38 | @(NSLayoutAttributeRight) : @"right", 39 | @(NSLayoutAttributeLeading) : @"leading", 40 | @(NSLayoutAttributeTrailing) : @"trailing", 41 | @(NSLayoutAttributeWidth) : @"width", 42 | @(NSLayoutAttributeHeight) : @"height", 43 | @(NSLayoutAttributeCenterX) : @"centerX", 44 | @(NSLayoutAttributeCenterY) : @"centerY", 45 | @(NSLayoutAttributeBaseline) : @"baseline", 46 | }; 47 | 48 | }); 49 | return descriptionMap; 50 | } 51 | 52 | 53 | + (NSDictionary *)layoutPriorityDescriptionsByValue { 54 | static dispatch_once_t once; 55 | static NSDictionary *descriptionMap; 56 | dispatch_once(&once, ^{ 57 | #if TARGET_OS_IPHONE 58 | descriptionMap = @{ 59 | @(MASLayoutPriorityDefaultHigh) : @"high", 60 | @(MASLayoutPriorityDefaultLow) : @"low", 61 | @(MASLayoutPriorityDefaultMedium) : @"medium", 62 | @(MASLayoutPriorityRequired) : @"required", 63 | @(MASLayoutPriorityFittingSizeLevel) : @"fitting size", 64 | }; 65 | #elif TARGET_OS_MAC 66 | descriptionMap = @{ 67 | @(MASLayoutPriorityDefaultHigh) : @"high", 68 | @(MASLayoutPriorityDragThatCanResizeWindow) : @"drag can resize window", 69 | @(MASLayoutPriorityDefaultMedium) : @"medium", 70 | @(MASLayoutPriorityWindowSizeStayPut) : @"window size stay put", 71 | @(MASLayoutPriorityDragThatCannotResizeWindow) : @"drag cannot resize window", 72 | @(MASLayoutPriorityDefaultLow) : @"low", 73 | @(MASLayoutPriorityFittingSizeCompression) : @"fitting size", 74 | @(MASLayoutPriorityRequired) : @"required", 75 | }; 76 | #endif 77 | }); 78 | return descriptionMap; 79 | } 80 | 81 | #pragma mark - description override 82 | 83 | + (NSString *)descriptionForObject:(id)obj { 84 | if ([obj respondsToSelector:@selector(mas_key)] && [obj mas_key]) { 85 | return [NSString stringWithFormat:@"%@:%@", [obj class], [obj mas_key]]; 86 | } 87 | return [NSString stringWithFormat:@"%@:%p", [obj class], obj]; 88 | } 89 | 90 | - (NSString *)description { 91 | NSMutableString *description = [[NSMutableString alloc] initWithString:@"<"]; 92 | 93 | [description appendString:[self.class descriptionForObject:self]]; 94 | 95 | [description appendFormat:@" %@", [self.class descriptionForObject:self.firstItem]]; 96 | if (self.firstAttribute != NSLayoutAttributeNotAnAttribute) { 97 | [description appendFormat:@".%@", [self.class.layoutAttributeDescriptionsByValue objectForKey:@(self.firstAttribute)]]; 98 | } 99 | 100 | [description appendFormat:@" %@", [self.class.layoutRelationDescriptionsByValue objectForKey:@(self.relation)]]; 101 | 102 | if (self.secondItem) { 103 | [description appendFormat:@" %@", [self.class descriptionForObject:self.secondItem]]; 104 | } 105 | if (self.secondAttribute != NSLayoutAttributeNotAnAttribute) { 106 | [description appendFormat:@".%@", [self.class.layoutAttributeDescriptionsByValue objectForKey:@(self.secondAttribute)]]; 107 | } 108 | 109 | if (self.multiplier != 1) { 110 | [description appendFormat:@" * %g", self.multiplier]; 111 | } 112 | 113 | if (self.constant) { 114 | if (self.secondAttribute == NSLayoutAttributeNotAnAttribute) { 115 | [description appendFormat:@" %g", self.constant]; 116 | } else { 117 | [description appendFormat:@" %@ %g", (self.constant < 0 ? @"-" : @"+"), ABS(self.constant)]; 118 | } 119 | } 120 | 121 | if (self.priority != MASLayoutPriorityRequired) { 122 | [description appendFormat:@" ^%@", [self.class.layoutPriorityDescriptionsByValue objectForKey:@(self.priority)] ?: [NSNumber numberWithDouble:self.priority]]; 123 | } 124 | 125 | [description appendString:@">"]; 126 | return description; 127 | } 128 | 129 | @end 130 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/View+MASAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+MASAdditions.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASUtilities.h" 10 | #import "MASConstraintMaker.h" 11 | #import "MASViewAttribute.h" 12 | 13 | /** 14 | * Provides constraint maker block 15 | * and convience methods for creating MASViewAttribute which are view + NSLayoutAttribute pairs 16 | */ 17 | @interface MAS_VIEW (MASAdditions) 18 | 19 | /** 20 | * following properties return a new MASViewAttribute with current view and appropriate NSLayoutAttribute 21 | */ 22 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_left; 23 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_top; 24 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_right; 25 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottom; 26 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leading; 27 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_trailing; 28 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_width; 29 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_height; 30 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerX; 31 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerY; 32 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_baseline; 33 | @property (nonatomic, strong, readonly) MASViewAttribute *(^mas_attribute)(NSLayoutAttribute attr); 34 | 35 | /** 36 | * a key to associate with this view 37 | */ 38 | @property (nonatomic, strong) id mas_key; 39 | 40 | /** 41 | * Finds the closest common superview between this view and another view 42 | * 43 | * @param view other view 44 | * 45 | * @return returns nil if common superview could not be found 46 | */ 47 | - (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view; 48 | 49 | /** 50 | * Creates a MASConstraintMaker with the callee view. 51 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing 52 | * 53 | * @param block scope within which you can build up the constraints which you wish to apply to the view. 54 | * 55 | * @return Array of created MASConstraints 56 | */ 57 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block; 58 | 59 | /** 60 | * Creates a MASConstraintMaker with the callee view. 61 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing. 62 | * If an existing constraint exists then it will be updated instead. 63 | * 64 | * @param block scope within which you can build up the constraints which you wish to apply to the view. 65 | * 66 | * @return Array of created/updated MASConstraints 67 | */ 68 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block; 69 | 70 | /** 71 | * Creates a MASConstraintMaker with the callee view. 72 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing. 73 | * All constraints previously installed for the view will be removed. 74 | * 75 | * @param block scope within which you can build up the constraints which you wish to apply to the view. 76 | * 77 | * @return Array of created/updated MASConstraints 78 | */ 79 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block; 80 | 81 | @end 82 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/View+MASAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+MASAdditions.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "View+MASAdditions.h" 10 | #import 11 | 12 | @implementation MAS_VIEW (MASAdditions) 13 | 14 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *))block { 15 | self.translatesAutoresizingMaskIntoConstraints = NO; 16 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self]; 17 | block(constraintMaker); 18 | return [constraintMaker install]; 19 | } 20 | 21 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *))block { 22 | self.translatesAutoresizingMaskIntoConstraints = NO; 23 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self]; 24 | constraintMaker.updateExisting = YES; 25 | block(constraintMaker); 26 | return [constraintMaker install]; 27 | } 28 | 29 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block { 30 | self.translatesAutoresizingMaskIntoConstraints = NO; 31 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self]; 32 | constraintMaker.removeExisting = YES; 33 | block(constraintMaker); 34 | return [constraintMaker install]; 35 | } 36 | 37 | #pragma mark - NSLayoutAttribute properties 38 | 39 | - (MASViewAttribute *)mas_left { 40 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeft]; 41 | } 42 | 43 | - (MASViewAttribute *)mas_top { 44 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTop]; 45 | } 46 | 47 | - (MASViewAttribute *)mas_right { 48 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeRight]; 49 | } 50 | 51 | - (MASViewAttribute *)mas_bottom { 52 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBottom]; 53 | } 54 | 55 | - (MASViewAttribute *)mas_leading { 56 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeading]; 57 | } 58 | 59 | - (MASViewAttribute *)mas_trailing { 60 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTrailing]; 61 | } 62 | 63 | - (MASViewAttribute *)mas_width { 64 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeWidth]; 65 | } 66 | 67 | - (MASViewAttribute *)mas_height { 68 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeHeight]; 69 | } 70 | 71 | - (MASViewAttribute *)mas_centerX { 72 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterX]; 73 | } 74 | 75 | - (MASViewAttribute *)mas_centerY { 76 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterY]; 77 | } 78 | 79 | - (MASViewAttribute *)mas_baseline { 80 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBaseline]; 81 | } 82 | 83 | - (MASViewAttribute *(^)(NSLayoutAttribute))mas_attribute 84 | { 85 | return ^(NSLayoutAttribute attr) { 86 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:attr]; 87 | }; 88 | } 89 | 90 | #pragma mark - associated properties 91 | 92 | - (id)mas_key { 93 | return objc_getAssociatedObject(self, @selector(mas_key)); 94 | } 95 | 96 | - (void)setMas_key:(id)key { 97 | objc_setAssociatedObject(self, @selector(mas_key), key, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 98 | } 99 | 100 | #pragma mark - heirachy 101 | 102 | - (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view { 103 | MAS_VIEW *closestCommonSuperview = nil; 104 | 105 | MAS_VIEW *secondViewSuperview = view; 106 | while (!closestCommonSuperview && secondViewSuperview) { 107 | MAS_VIEW *firstViewSuperview = self; 108 | while (!closestCommonSuperview && firstViewSuperview) { 109 | if (secondViewSuperview == firstViewSuperview) { 110 | closestCommonSuperview = secondViewSuperview; 111 | } 112 | firstViewSuperview = firstViewSuperview.superview; 113 | } 114 | secondViewSuperview = secondViewSuperview.superview; 115 | } 116 | return closestCommonSuperview; 117 | } 118 | 119 | @end 120 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/Masonry/Masonry/View+MASShorthandAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+MASShorthandAdditions.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 22/07/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "View+MASAdditions.h" 10 | 11 | #ifdef MAS_SHORTHAND 12 | 13 | /** 14 | * Shorthand view additions without the 'mas_' prefixes, 15 | * only enabled if MAS_SHORTHAND is defined 16 | */ 17 | @interface MAS_VIEW (MASShorthandAdditions) 18 | 19 | @property (nonatomic, strong, readonly) MASViewAttribute *left; 20 | @property (nonatomic, strong, readonly) MASViewAttribute *top; 21 | @property (nonatomic, strong, readonly) MASViewAttribute *right; 22 | @property (nonatomic, strong, readonly) MASViewAttribute *bottom; 23 | @property (nonatomic, strong, readonly) MASViewAttribute *leading; 24 | @property (nonatomic, strong, readonly) MASViewAttribute *trailing; 25 | @property (nonatomic, strong, readonly) MASViewAttribute *width; 26 | @property (nonatomic, strong, readonly) MASViewAttribute *height; 27 | @property (nonatomic, strong, readonly) MASViewAttribute *centerX; 28 | @property (nonatomic, strong, readonly) MASViewAttribute *centerY; 29 | @property (nonatomic, strong, readonly) MASViewAttribute *baseline; 30 | @property (nonatomic, strong, readonly) MASViewAttribute *(^attribute)(NSLayoutAttribute attr); 31 | 32 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block; 33 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block; 34 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block; 35 | 36 | @end 37 | 38 | #define MAS_ATTR_FORWARD(attr) \ 39 | - (MASViewAttribute *)attr { \ 40 | return [self mas_##attr]; \ 41 | } 42 | 43 | @implementation MAS_VIEW (MASShorthandAdditions) 44 | 45 | MAS_ATTR_FORWARD(top); 46 | MAS_ATTR_FORWARD(left); 47 | MAS_ATTR_FORWARD(bottom); 48 | MAS_ATTR_FORWARD(right); 49 | MAS_ATTR_FORWARD(leading); 50 | MAS_ATTR_FORWARD(trailing); 51 | MAS_ATTR_FORWARD(width); 52 | MAS_ATTR_FORWARD(height); 53 | MAS_ATTR_FORWARD(centerX); 54 | MAS_ATTR_FORWARD(centerY); 55 | MAS_ATTR_FORWARD(baseline); 56 | 57 | - (MASViewAttribute *(^)(NSLayoutAttribute))attribute { 58 | return [self mas_attribute]; 59 | } 60 | 61 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *))block { 62 | return [self mas_makeConstraints:block]; 63 | } 64 | 65 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *))block { 66 | return [self mas_updateConstraints:block]; 67 | } 68 | 69 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *))block { 70 | return [self mas_remakeConstraints:block]; 71 | } 72 | 73 | @end 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/UIView+Frame.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Frame.h 3 | // CharlesCustomTableViewController 4 | // 5 | // Created by Charles on 16/7/21. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIView (Frame) 12 | 13 | 14 | /** 15 | * 起点x坐标 16 | */ 17 | @property (nonatomic, assign) CGFloat x; 18 | /** 19 | * 起点y坐标 20 | */ 21 | @property (nonatomic, assign) CGFloat y; 22 | /** 23 | * 中心点x坐标 24 | */ 25 | @property (nonatomic, assign) CGFloat centerX; 26 | /** 27 | * 中心点y坐标 28 | */ 29 | @property (nonatomic, assign) CGFloat centerY; 30 | /** 31 | * 宽度 32 | */ 33 | @property (nonatomic, assign) CGFloat width; 34 | /** 35 | * 高度 36 | */ 37 | @property (nonatomic, assign) CGFloat height; 38 | /** 39 | * 顶部 40 | */ 41 | @property (nonatomic, assign) CGFloat top; 42 | /** 43 | * 底部 44 | */ 45 | @property (nonatomic, assign) CGFloat bottom; 46 | /** 47 | * 左边 48 | */ 49 | @property (nonatomic, assign) CGFloat left; 50 | /** 51 | * 右边 52 | */ 53 | @property (nonatomic, assign) CGFloat right; 54 | /** 55 | * size 56 | */ 57 | @property (nonatomic, assign) CGSize size; 58 | /** 59 | * 起点坐标 60 | */ 61 | @property (nonatomic, assign) CGPoint origin; 62 | @end 63 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/UIView+Frame.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Frame.m 3 | // CharlesCustomTableViewController 4 | // 5 | // Created by Charles on 16/7/21. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import "UIView+Frame.h" 10 | 11 | @implementation UIView (Frame) 12 | 13 | - (void)setX:(CGFloat)x { 14 | CGRect frame = self.frame; 15 | frame.origin.x = x; 16 | self.frame = frame; 17 | } 18 | 19 | - (void)setY:(CGFloat)y { 20 | CGRect frame = self.frame; 21 | frame.origin.y = y; 22 | self.frame = frame; 23 | } 24 | 25 | - (CGFloat)x { 26 | return self.frame.origin.x; 27 | } 28 | 29 | - (CGFloat)y { 30 | return self.frame.origin.y; 31 | } 32 | 33 | - (void)setCenterX:(CGFloat)centerX { 34 | 35 | CGPoint center = self.center; 36 | center.x = centerX; 37 | self.center = center; 38 | 39 | } 40 | 41 | - (CGFloat)centerX { 42 | return self.center.x; 43 | } 44 | 45 | - (void)setCenterY:(CGFloat)centerY{ 46 | CGPoint center = self.center; 47 | 48 | center.y = centerY; 49 | 50 | self.center = center; 51 | } 52 | 53 | - (CGFloat)centerY { 54 | return self.center.y; 55 | } 56 | 57 | - (void)setWidth:(CGFloat)width { 58 | CGRect frame = self.frame; 59 | frame.size.width = width; 60 | self.frame = frame; 61 | } 62 | 63 | - (void)setHeight:(CGFloat)height { 64 | CGRect frame = self.frame; 65 | frame.size.height = height; 66 | self.frame = frame; 67 | } 68 | 69 | - (CGFloat)height { 70 | return self.frame.size.height; 71 | } 72 | 73 | - (CGFloat)width { 74 | return self.frame.size.width; 75 | } 76 | 77 | - (void)setSize:(CGSize)size { 78 | CGRect frame = self.frame; 79 | frame.size = size; 80 | self.frame = frame; 81 | } 82 | 83 | - (CGSize)size { 84 | return self.frame.size; 85 | } 86 | 87 | - (void)setOrigin:(CGPoint)origin { 88 | CGRect frame = self.frame; 89 | frame.origin = origin; 90 | self.frame = frame; 91 | } 92 | 93 | - (CGPoint)origin { 94 | return self.frame.origin; 95 | } 96 | 97 | - (CGFloat)top { 98 | return self.frame.origin.y; 99 | } 100 | 101 | - (void)setTop:(CGFloat)top { 102 | CGRect frame = self.frame; 103 | frame.origin.y = top; 104 | self.frame = frame; 105 | } 106 | 107 | - (CGFloat)left { 108 | return self.frame.origin.x; 109 | } 110 | 111 | - (void)setLeft:(CGFloat)left { 112 | CGRect frame = self.frame; 113 | frame.origin.x = left; 114 | self.frame = frame; 115 | } 116 | 117 | - (CGFloat)bottom { 118 | return self.frame.size.height + self.frame.origin.y; 119 | } 120 | 121 | - (void)setBottom:(CGFloat)bottom { 122 | CGRect frame = self.frame; 123 | frame.origin.y = bottom - frame.size.height; 124 | self.frame = frame; 125 | } 126 | 127 | - (CGFloat)right { 128 | return self.frame.size.width + self.frame.origin.x; 129 | } 130 | 131 | - (void)setRight:(CGFloat)right { 132 | CGRect frame = self.frame; 133 | frame.origin.x = right - frame.size.width; 134 | self.frame = frame; 135 | } 136 | @end 137 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/UIView+XRNib.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+XRNib.h 3 | // CharlesCustomTableViewController 4 | // 5 | // Created by Charles on 16/7/21. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIView (XRNib) 12 | 13 | + (instancetype)nib; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/UIView+XRNib.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+XRNib.m 3 | // CharlesCustomTableViewController 4 | // 5 | // Created by Charles on 16/7/21. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import "UIView+XRNib.h" 10 | 11 | @implementation UIView (XRNib) 12 | 13 | + (instancetype)nib { 14 | NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:[self description] owner:nil options:nil]; 15 | if (nibs.count) { 16 | return nibs.firstObject; 17 | } 18 | return nil; 19 | } 20 | @end 21 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/UIView+XRTap.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+XRTap.h 3 | // CharlesCustomTableViewController 4 | // 5 | // Created by Charles on 16/7/21. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIView (XRTap) 12 | 13 | /** 14 | * 动态添加手势 15 | */ 16 | - (void)setTapActionWithBlock:(void (^)(void))block ; 17 | @end 18 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/UIView+XRTap.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+XRTap.m 3 | // CharlesCustomTableViewController 4 | // 5 | // Created by Charles on 16/7/21. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import "UIView+XRTap.h" 10 | 11 | #import 12 | 13 | @implementation UIView (XRTap) 14 | 15 | /** 16 | * 动态添加手势 17 | */ 18 | static const char *ActionHandlerTapGestureKey; 19 | 20 | - (void)setTapActionWithBlock:(void (^)(void))block { 21 | 22 | self.userInteractionEnabled = YES; 23 | 24 | UITapGestureRecognizer *gesture = objc_getAssociatedObject(self, &ActionHandlerTapGestureKey); 25 | 26 | if (!gesture) { 27 | gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleActionForTapGesture:)]; 28 | [self addGestureRecognizer:gesture]; 29 | objc_setAssociatedObject(self, &ActionHandlerTapGestureKey, gesture, OBJC_ASSOCIATION_RETAIN); 30 | } 31 | 32 | objc_setAssociatedObject(self, &ActionHandlerTapGestureKey, block, OBJC_ASSOCIATION_COPY); 33 | } 34 | 35 | - (void)handleActionForTapGesture:(UITapGestureRecognizer *)gesture { 36 | if (gesture.state == UIGestureRecognizerStateRecognized) { 37 | void(^action)(void) = objc_getAssociatedObject(self, &ActionHandlerTapGestureKey); 38 | if (action) { 39 | action(); 40 | } 41 | } 42 | } 43 | @end 44 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/XRBaseTableHeaderFooterView.h: -------------------------------------------------------------------------------- 1 | // 2 | // XRBaseTableHeaderFooterView.h 3 | // Charles 4 | // 5 | // Created by Charles on 16/7/6. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface XRBaseTableHeaderFooterView : UITableViewHeaderFooterView 12 | 13 | + (instancetype)headerFooterViewWithTableView:(UITableView *)tableView; 14 | 15 | + (instancetype)nibHeaderFooterViewWithTableView:(UITableView *)tableView; 16 | 17 | + (NSString *)identifier; 18 | 19 | + (NSString *)nibIdentifier; 20 | @end 21 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/XRBaseTableHeaderFooterView.m: -------------------------------------------------------------------------------- 1 | // 2 | // XRBaseTableHeaderFooterView.m 3 | // Charles 4 | // 5 | // Created by Charles on 16/7/6. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import "XRBaseTableHeaderFooterView.h" 10 | #import "UIView+XRNib.h" 11 | 12 | @implementation XRBaseTableHeaderFooterView 13 | 14 | + (instancetype)headerFooterViewWithTableView:(UITableView *)tableView { 15 | if (tableView == nil) { 16 | return [[self alloc] init]; 17 | } 18 | NSString *classname = NSStringFromClass([self class]); 19 | NSString *identifer = [classname stringByAppendingString:@"HeaderFooterID"]; 20 | [tableView registerClass:[self class] forHeaderFooterViewReuseIdentifier:identifer]; 21 | return [tableView dequeueReusableHeaderFooterViewWithIdentifier:identifer]; 22 | } 23 | 24 | + (instancetype)nibHeaderFooterViewWithTableView:(UITableView *)tableView { 25 | if (tableView == nil) { 26 | return [self nib]; 27 | } 28 | NSString *classname = NSStringFromClass([self class]); 29 | NSString *identifer = [classname stringByAppendingString:@"nibHeaderFooterID"]; 30 | UINib *nib = [UINib nibWithNibName:classname bundle:nil]; 31 | [tableView registerNib:nib forHeaderFooterViewReuseIdentifier:identifer]; 32 | return [tableView dequeueReusableHeaderFooterViewWithIdentifier:identifer]; 33 | } 34 | 35 | + (NSString *)identifier { 36 | return [[self description] stringByAppendingString:@"HeaderFooterID"]; 37 | } 38 | 39 | + (NSString *)nibIdentifier { 40 | return [[self description] stringByAppendingString:@"nibHeaderFooterID"]; 41 | } 42 | @end 43 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/XRBaseTableView.h: -------------------------------------------------------------------------------- 1 | // 2 | // XRBaseTableView.h 3 | // 4 | // 5 | // Created by Charles on 16/6/20. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NS_ENUM(NSInteger, XRBaseTableViewRowAnimation) { 12 | Fade = UITableViewRowAnimationFade, 13 | Right = UITableViewRowAnimationRight, // slide in from right (or out to right) 14 | Left = UITableViewRowAnimationLeft, 15 | Top = UITableViewRowAnimationTop, 16 | Bottom = UITableViewRowAnimationBottom, 17 | None = UITableViewRowAnimationNone, // available in iOS 3.0 18 | Middle = UITableViewRowAnimationMiddle, // available in iOS 3.2. attempts to keep cell centered in the space it will/did occupy 19 | Automatic = 100 // available in iOS 5.0. chooses an appropriate animation style for you 20 | }; 21 | @class XRBaseTableViewCell; 22 | 23 | @interface XRBaseTableView : UITableView 24 | 25 | - (void)xr_updateWithUpdateBlock:(void(^)(XRBaseTableView *tableView ))updateBlock; 26 | 27 | - (UITableViewCell *)xr_cellForRowAtIndexPath:(NSIndexPath *)indexPath; 28 | 29 | /** 注册普通的UITableViewCell*/ 30 | - (void)xr_registerCellClass:(Class)cellClass identifier:(NSString *)identifier; 31 | 32 | /** 注册一个从xib中加载的UITableViewCell*/ 33 | - (void)xr_registerCellNib:(Class)cellNib nibIdentifier:(NSString *)nibIdentifier; 34 | 35 | /** 注册一个普通的UITableViewHeaderFooterView*/ 36 | - (void)xr_registerHeaderFooterClass:(Class)headerFooterClass identifier:(NSString *)identifier; 37 | 38 | /** 注册一个从xib中加载的UITableViewHeaderFooterView*/ 39 | - (void)xr_registerHeaderFooterNib:(Class)headerFooterNib nibIdentifier:(NSString *)nibIdentifier; 40 | 41 | #pragma mark - 只对已经存在的cell进行刷新,没有类似于系统的 如果行不存在,默认insert操作 42 | /** 刷新单行、动画默认*/ 43 | - (void)xr_reloadSingleRowAtIndexPath:(NSIndexPath *)indexPath; 44 | 45 | /** 刷新单行、动画默认*/ 46 | - (void)xr_reloadSingleRowAtIndexPath:(NSIndexPath *)indexPath animation:(XRBaseTableViewRowAnimation)animation; 47 | 48 | /** 刷新多行、动画默认*/ 49 | - (void)xr_reloadRowsAtIndexPaths:(NSArray *)indexPaths; 50 | 51 | /** 刷新多行、动画默认*/ 52 | - (void)xr_reloadRowsAtIndexPaths:(NSArray *)indexPaths animation:(XRBaseTableViewRowAnimation)animation; 53 | 54 | /** 刷新某个section、动画默认*/ 55 | - (void)xr_reloadSingleSection:(NSInteger)section; 56 | 57 | /** 刷新某个section、动画自定义*/ 58 | - (void)xr_reloadSingleSection:(NSInteger)section animation:(XRBaseTableViewRowAnimation)animation; 59 | 60 | /** 刷新多个section、动画默认*/ 61 | - (void)xr_reloadSections:(NSArray *)sections; 62 | 63 | /** 刷新多个section、动画自定义*/ 64 | - (void)xr_reloadSections:(NSArray *)sections animation:(XRBaseTableViewRowAnimation)animation; 65 | 66 | #pragma mark - 对cell进行删除操作 67 | /** 删除单行、动画默认*/ 68 | - (void)xr_deleteSingleRowAtIndexPath:(NSIndexPath *)indexPath; 69 | 70 | /** 删除单行、动画自定义*/ 71 | - (void)xr_deleteSingleRowAtIndexPath:(NSIndexPath *)indexPath animation:(XRBaseTableViewRowAnimation)animation; 72 | 73 | /** 删除多行、动画默认*/ 74 | - (void)xr_deleteRowsAtIndexPaths:(NSArray *)indexPaths; 75 | 76 | /** 删除多行、动画自定义*/ 77 | - (void)xr_deleteRowsAtIndexPaths:(NSArray *)indexPaths animation:(XRBaseTableViewRowAnimation)animation; 78 | 79 | /** 删除某个section、动画默认*/ 80 | - (void)xr_deleteSingleSection:(NSInteger)section; 81 | 82 | /** 删除某个section、动画自定义*/ 83 | - (void)xr_deleteSingleSection:(NSInteger)section animation:(XRBaseTableViewRowAnimation)animation; 84 | 85 | /** 删除多个section*/ 86 | - (void)xr_deleteSections:(NSArray *)sections; 87 | 88 | /** 删除多个section*/ 89 | - (void)xr_deleteSections:(NSArray *)sections animation:(XRBaseTableViewRowAnimation)animation; 90 | 91 | #pragma mark - 对cell进行删除操作 92 | /** 增加单行 动画无*/ 93 | - (void)xr_insertSingleRowAtIndexPath:(NSIndexPath *)indexPath; 94 | 95 | /** 增加单行,动画自定义*/ 96 | - (void)xr_insertSingleRowAtIndexPath:(NSIndexPath *)indexPath animation:(XRBaseTableViewRowAnimation)animation; 97 | 98 | /** 增加单section,动画无*/ 99 | - (void)xr_insertSingleSection:(NSInteger)section; 100 | 101 | /** 增加单section,动画自定义*/ 102 | - (void)xr_insertSingleSection:(NSInteger)section animation:(XRBaseTableViewRowAnimation)animation; 103 | 104 | /** 增加多行,动画无*/ 105 | - (void)xr_insertRowsAtIndexPaths:(NSArray *)indexPaths; 106 | 107 | /** 增加多行,动画自定义*/ 108 | - (void)xr_insertRowsAtIndexPaths:(NSArray *)indexPaths animation:(XRBaseTableViewRowAnimation)animation; 109 | 110 | /** 增加多section,动画无*/ 111 | - (void)xr_insertSections:(NSArray *)sections; 112 | 113 | /** 增加多section,动画自定义*/ 114 | - (void)xr_insertSections:(NSArray *)sections animation:(XRBaseTableViewRowAnimation)animation; 115 | @end 116 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/XRBaseTableViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // XRBaseTableViewCell.h 3 | // Charles 4 | // 5 | // Created by Charles on 16/6/21. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "XRBaseTableView.h" 11 | 12 | @interface XRBaseTableViewCell : UITableViewCell 13 | /** 14 | * 快速创建一个不是从xib中加载的tableview cell 15 | */ 16 | + (instancetype)cellWithTableView:(UITableView *)tableView; 17 | 18 | /** 19 | * 快速创建一个从xib中加载的tableview cell 20 | */ 21 | + (instancetype)nibCellWithTableView:(UITableView *)tableView; 22 | 23 | @property (nonatomic, copy) NSString *identifier; 24 | 25 | @property (nonatomic, copy) NSString *nibIdentifier; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/XRBaseTableViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // XRBaseTableViewCell.m 3 | // Charles 4 | // 5 | // Created by Charles on 16/6/21. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import "XRBaseTableViewCell.h" 10 | #import "UIView+XRNib.h" 11 | 12 | @implementation XRBaseTableViewCell 13 | 14 | - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 15 | if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { 16 | self.selectionStyle = UITableViewCellSelectionStyleNone; 17 | self.contentView.backgroundColor = [UIColor whiteColor]; 18 | } 19 | return self; 20 | } 21 | 22 | + (instancetype)cellWithTableView:(UITableView *)tableView { 23 | if (tableView == nil) { 24 | return [[self alloc] init]; 25 | } 26 | NSString *classname = NSStringFromClass([self class]); 27 | NSString *identifier = [classname stringByAppendingString:@"CellID"]; 28 | [tableView registerClass:[self class] forCellReuseIdentifier:identifier]; 29 | return [tableView dequeueReusableCellWithIdentifier:identifier]; 30 | } 31 | 32 | + (instancetype)nibCellWithTableView:(UITableView *)tableView { 33 | if (tableView == nil) { 34 | return [self nib]; 35 | } 36 | NSString *classname = NSStringFromClass([self class]); 37 | NSString *identifier = [classname stringByAppendingString:@"nibCellID"]; 38 | UINib *nib = [UINib nibWithNibName:classname bundle:nil]; 39 | [tableView registerNib:nib forCellReuseIdentifier:identifier]; 40 | return [tableView dequeueReusableCellWithIdentifier:identifier]; 41 | } 42 | 43 | - (NSString *)nibIdentifier { 44 | return [[self description] stringByAppendingString:@"nibCellID"]; 45 | } 46 | 47 | - (NSString *)identifier { 48 | return [[self description] stringByAppendingString:@"CellID"]; 49 | } 50 | @end 51 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/XRBaseTableViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // XRBaseTableViewController.h 3 | // Charles 4 | // 5 | // Created by Charles on 16/7/16. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class XRBaseTableView, XRBaseTableViewCell; 12 | 13 | typedef void(^XRTableVcCellSelectedHandle)(XRBaseTableViewCell *cell, NSIndexPath *indexPath); 14 | 15 | typedef NS_ENUM(NSUInteger, XRBaseTableVcRefreshType) { 16 | /** 无法刷新*/ 17 | XRBaseTableVcRefreshTypeNone = 0, 18 | /** 只能刷新*/ 19 | XRBaseTableVcRefreshTypeOnlyCanRefresh, 20 | /** 只能上拉加载*/ 21 | XRBaseTableVcRefreshTypeOnlyCanLoadMore, 22 | /** 能刷新*/ 23 | XRBaseTableVcRefreshTypeRefreshAndLoadMore 24 | }; 25 | @class XRBaseTableViewController; 26 | 27 | @protocol XRBaseTableViewControllerDelegate 28 | - (void)baseTableViewController:(XRBaseTableViewController *)controller didSelectCellAtIndexPath:(NSIndexPath *)indexPath; 29 | @end 30 | 31 | @interface XRBaseTableViewController : UIViewController 32 | 33 | /** 设置导航栏右边的item*/ 34 | - (void)xr_setUpNavRightItemTitle:(NSString *)itemTitle handle:(void(^)(NSString *rightItemTitle))handle; 35 | 36 | /** 设置导航栏左边的item*/ 37 | - (void)xr_setUpNavLeftItemTitle:(NSString *)itemTitle handle:(void(^)(NSString *leftItemTitle))handle; 38 | 39 | /** 监听通知*/ 40 | - (void)xr_observeNotiWithNotiName:(NSString *)notiName action:(SEL)action; 41 | 42 | /** 隐藏statusBar*/ 43 | @property (nonatomic, assign) BOOL hiddenStatusBar; 44 | 45 | /** statusBar风格*/ 46 | @property (nonatomic, assign) UIStatusBarStyle barStyle; 47 | 48 | /** 导航右边Item*/ 49 | @property (nonatomic, strong) UIBarButtonItem *navRightItem; 50 | 51 | /** 点击某个cell的代理,子类可以继承协议继续扩充*/ 52 | @property (nonatomic, weak) id delegate; 53 | 54 | /** 标题*/ 55 | @property (nonatomic, copy) NSString *navItemTitle; 56 | 57 | /** 表视图*/ 58 | @property (nonatomic, weak) XRBaseTableView *tableView; 59 | 60 | /** 表视图偏移*/ 61 | @property (nonatomic, assign) UIEdgeInsets tableEdgeInset; 62 | 63 | /** 分割线颜色*/ 64 | @property (nonatomic, assign) UIColor *sepLineColor; 65 | 66 | /** 数据源数量*/ 67 | @property (nonatomic, strong) NSMutableArray *dataArray; 68 | 69 | /** 加载刷新类型*/ 70 | @property (nonatomic, assign) XRBaseTableVcRefreshType refreshType; 71 | 72 | /** 是否需要系统的cell的分割线*/ 73 | @property (nonatomic, assign) BOOL needCellSepLine; 74 | 75 | /** 刷新数据*/ 76 | - (void)xr_reloadData; 77 | 78 | /** 开始下拉*/ 79 | - (void)xr_beginRefresh; 80 | 81 | /** 停止刷新*/ 82 | - (void)xr_endRefresh; 83 | 84 | /** 停止上拉加载*/ 85 | - (void)xr_endLoadMore; 86 | 87 | /** 隐藏刷新*/ 88 | - (void)xr_hiddenRrefresh; 89 | 90 | /** 隐藏上拉加载*/ 91 | - (void)xr_hiddenLoadMore; 92 | 93 | /** 提示没有更多信息*/ 94 | - (void)xr_noticeNoMoreData; 95 | 96 | /** 是否在下拉刷新*/ 97 | @property (nonatomic, assign, readonly) BOOL isHeaderRefreshing; 98 | 99 | /** 是否在上拉加载*/ 100 | @property (nonatomic, assign, readonly) BOOL isFooterRefreshing; 101 | 102 | #pragma mark - 子类去重写 103 | /** 分组数量*/ 104 | - (NSInteger)xr_numberOfSections; 105 | 106 | /** 某个分组的cell数量*/ 107 | - (NSInteger)xr_numberOfRowsInSection:(NSInteger)section; 108 | 109 | /** 某行的cell*/ 110 | - (XRBaseTableViewCell *)xr_cellAtIndexPath:(NSIndexPath *)indexPath; 111 | 112 | /** 点击某行*/ 113 | - (void)xr_didSelectCellWithHandle:(XRTableVcCellSelectedHandle)handle; 114 | 115 | /** 某行行高*/ 116 | - (CGFloat)xr_cellheightAtIndexPath:(NSIndexPath *)indexPath; 117 | 118 | /** 某个组头*/ 119 | - (UIView *)xr_headerAtSection:(NSInteger)section; 120 | 121 | /** 某个组尾*/ 122 | - (UIView *)xr_footerAtSection:(NSInteger)section; 123 | 124 | /** 某个组头高度*/ 125 | - (CGFloat)xr_sectionHeaderHeightAtSection:(NSInteger)section; 126 | 127 | /** 某个组尾高度*/ 128 | - (CGFloat)xr_sectionFooterHeaderAtSection:(NSInteger)section; 129 | 130 | /** 分割线偏移*/ 131 | - (UIEdgeInsets)xr_sepEdgeInsetsAtIndexPath:(NSIndexPath *)indexPath; 132 | 133 | #pragma mark - 子类去继承 134 | /** 刷新方法*/ 135 | - (void)xr_refresh; 136 | 137 | /** 上拉加载方法*/ 138 | - (void)xr_loadMore; 139 | @end 140 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/XRSlideOperationViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // XRSlideOperationViewCell.h 3 | // Charles 4 | // 5 | // Created by Charles on 16/7/15. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 滑动cell 执行某些操作 8 | 9 | #import "XRBaseTableViewCell.h" 10 | 11 | @class XRSlideOperationViewCell; 12 | @protocol XRSlideOperationViewCellDataSource 13 | 14 | /** 几个按钮*/ 15 | - (NSInteger)numberOfItemsInSlideOperation:(XRSlideOperationViewCell *)cell; 16 | /** 按钮*/ 17 | - (UIButton *)slideOperationViewCell:(XRSlideOperationViewCell *)cell buttonAtIndex:(NSInteger)index; 18 | /** 按钮大小*/ 19 | - (CGSize)slideOperationViewCell:(XRSlideOperationViewCell *)cell sizeAtIndex:(NSInteger)index; 20 | 21 | @end 22 | 23 | @protocol XRSlideOperationViewCellDelegate 24 | 25 | /** 点击事件*/ 26 | - (void)slideOperationViewCell:(XRSlideOperationViewCell *)cell didSelectButtonAtIndex:(NSInteger)index; 27 | /** 开始滑动的时候*/ 28 | - (void)slideOperationViewCellDidBeginSlide:(XRSlideOperationViewCell *)cell; 29 | 30 | @end 31 | 32 | @interface XRSlideOperationViewCell : XRBaseTableViewCell 33 | 34 | @property (nonatomic, weak) id dataSource; 35 | @property (nonatomic, weak) id delegate; 36 | /** 容器视图 类似于contentView*/ 37 | @property (nonatomic, weak) UIView *cellContentView; 38 | @end 39 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/XRUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // XRUtils.h 3 | // Charles 4 | // 5 | // Created by Charles on 16/6/20. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | typedef void(^XRRefreshAndLoadMoreHandle)(void); 10 | 11 | #import 12 | #import 13 | 14 | /** 15 | * 弱指针 16 | */ 17 | #define WeakSelf(weakSelf) __weak __typeof(&*self)weakSelf = self; 18 | @interface XRUtils : NSObject 19 | 20 | /** 开始下拉刷新 */ 21 | + (void)beginPullRefreshForScrollView:(UIScrollView *)scrollView; 22 | 23 | /** 判断头部是否在刷新 */ 24 | + (BOOL)headerIsRefreshForScrollView:(UIScrollView *)scrollView; 25 | 26 | /** 判断是否尾部在刷新 */ 27 | + (BOOL)footerIsLoadingForScrollView:(UIScrollView *)scrollView; 28 | 29 | /** 提示没有更多数据的情况 */ 30 | + (void)noticeNoMoreDataForScrollView:(UIScrollView *)scrollView; 31 | 32 | /** 重置footer */ 33 | + (void)resetNoMoreDataForScrollView:(UIScrollView *)scrollView; 34 | 35 | /** 停止下拉刷新 */ 36 | + (void)endRefreshForScrollView:(UIScrollView *)scrollView; 37 | 38 | /** 停止上拉加载 */ 39 | + (void)endLoadMoreForScrollView:(UIScrollView *)scrollView; 40 | 41 | /** 隐藏footer */ 42 | + (void)hiddenFooterForScrollView:(UIScrollView *)scrollView; 43 | 44 | /** 隐藏header */ 45 | + (void)hiddenHeaderForScrollView:(UIScrollView *)scrollView; 46 | 47 | /** 下拉刷新 */ 48 | + (void)addLoadMoreForScrollView:(UIScrollView *)scrollView 49 | loadMoreCallBack:(XRRefreshAndLoadMoreHandle)loadMoreCallBackBlock; 50 | 51 | /** 上拉加载 */ 52 | + (void)addPullRefreshForScrollView:(UIScrollView *)scrollView 53 | pullRefreshCallBack:(XRRefreshAndLoadMoreHandle)pullRefreshCallBackBlock; 54 | 55 | /** 返回有效的字符串 将string作为参数传递的好处是 及时stirng是nil 也会有返回值@"" */ 56 | + (NSString *)validString:(NSString *)string; 57 | 58 | /** 判断字符串是否为空 */ 59 | + (BOOL)isBlankString:(NSString *)string; 60 | 61 | 62 | /** 获取视频某一帧的图像*/ 63 | + (UIImage *)xr_thumbnailImageForVideo:(NSURL *)videoURL atTime:(NSTimeInterval)time; 64 | @end 65 | -------------------------------------------------------------------------------- /CustomTableVc/Charles/XRUtils.m: -------------------------------------------------------------------------------- 1 | // 2 | // XRUtils.m 3 | // Charles 4 | // 5 | // Created by Charles on 16/6/20. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import "XRUtils.h" 10 | #import "MJRefresh.h" 11 | #import 12 | #import 13 | 14 | @implementation XRUtils 15 | 16 | + (NSInteger)totalDataCountForScrollView:(UIScrollView *)scrollView { 17 | NSInteger totalCount = 0; 18 | if ([scrollView isKindOfClass:[UITableView class]]) { 19 | UITableView *tableView = (UITableView *)scrollView; 20 | 21 | for (NSInteger section = 0; section 16 | 17 | @end 18 | 19 | @implementation Demo1ViewController 20 | 21 | - (void)viewDidLoad { 22 | [super viewDidLoad]; 23 | 24 | [self loadData]; 25 | 26 | // 设置刷新试试 27 | self.refreshType = XRBaseTableVcRefreshTypeRefreshAndLoadMore; 28 | 29 | // 设置位置 30 | // self.tableEdgeInset = UIEdgeInsetsMake(40, 0, 0, 0); 31 | // 基类控制器和基类tableview和基类cell中还有好多东西 32 | [self xr_reloadData]; 33 | } 34 | 35 | - (void)loadData { 36 | 37 | for (int i = 0 ; i < 20; i++) { 38 | if (i % 2 == 0) { 39 | [self.dataArray addObject:@(YES)]; 40 | } else { 41 | [self.dataArray addObject:@(NO)]; 42 | } 43 | } 44 | } 45 | 46 | - (void)xr_refresh { 47 | // 调用super方法 48 | [super xr_refresh]; 49 | 50 | [self.dataArray removeAllObjects]; 51 | 52 | dispatch_async(dispatch_get_global_queue(0, 0), ^{ 53 | 54 | // 1. 加载数据 55 | [self loadData]; 56 | 57 | dispatch_async(dispatch_get_main_queue(), ^{ 58 | 59 | // 模拟网络请求 60 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 61 | // 2. 加载数据完成 62 | [self xr_endRefresh]; 63 | 64 | // 3.刷新界面 65 | [self xr_reloadData]; 66 | }); 67 | }); 68 | }); 69 | 70 | } 71 | 72 | - (void)xr_loadMore { 73 | [super xr_loadMore]; 74 | 75 | dispatch_async(dispatch_get_global_queue(0, 0), ^{ 76 | 77 | // 1. 加载数据 78 | int count = (int)self.dataArray.count; 79 | for (int i = count; i < count + 20; i++) { 80 | if (i % 2 == 0) { 81 | [self.dataArray addObject:@(YES)]; 82 | } else { 83 | [self.dataArray addObject:@(NO)]; 84 | } 85 | } 86 | dispatch_async(dispatch_get_main_queue(), ^{ 87 | 88 | // 模拟网络请求 89 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 90 | 91 | // 2. 加载数据完成 92 | [self xr_endLoadMore]; 93 | 94 | // 3. 刷新界面 95 | [self xr_reloadData]; 96 | }); 97 | }); 98 | }); 99 | } 100 | 101 | - (NSInteger)xr_numberOfSections { 102 | return 1; 103 | } 104 | 105 | - (NSInteger)xr_numberOfRowsInSection:(NSInteger)section { 106 | return self.dataArray.count; 107 | } 108 | 109 | - (CGFloat)xr_cellheightAtIndexPath:(NSIndexPath *)indexPath { 110 | return 100; 111 | } 112 | 113 | - (XRBaseTableViewCell *)xr_cellAtIndexPath:(NSIndexPath *)indexPath { 114 | 115 | NSNumber *boolFlag = self.dataArray[indexPath.row]; 116 | 117 | if (boolFlag.boolValue) { 118 | 119 | XRBaseTableViewCell *cell = [XRBaseTableViewCell cellWithTableView:self.tableView]; 120 | cell.textLabel.text = @"这就是一个普通的cell"; 121 | return cell; 122 | 123 | } else { 124 | XRSlideTestCell *cell = [XRSlideTestCell cellWithTableView:self.tableView]; 125 | cell.name = @"这是一个可以滑动的cell,不信你左滑试试"; 126 | cell.delegate = self; 127 | cell.dataSource = self; 128 | cell.cellContentView.backgroundColor = [UIColor lightGrayColor]; 129 | // 加载内容加到这上面。。 130 | return cell; 131 | } 132 | return [[XRBaseTableViewCell alloc] init]; 133 | } 134 | 135 | - (NSInteger)numberOfItemsInSlideOperation:(XRSlideOperationViewCell *)cell { 136 | return 3; 137 | } 138 | 139 | 140 | #pragma mark - 141 | - (UIButton *)slideOperationViewCell:(XRSlideOperationViewCell *)cell buttonAtIndex:(NSInteger)index { 142 | UIButton *btn = [[UIButton alloc] init]; 143 | [btn setTitle:[NSString stringWithFormat:@"第%ld个", index] forState:UIControlStateNormal]; 144 | [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 145 | UIColor *bgColor = [UIColor redColor]; 146 | if (index == 0) { 147 | bgColor = [UIColor redColor]; 148 | } else if (index == 1) { 149 | bgColor = [UIColor greenColor]; 150 | } else if (index == 2) { 151 | bgColor = [UIColor whiteColor]; 152 | } 153 | [btn setBackgroundColor:bgColor]; 154 | return btn; 155 | } 156 | 157 | - (void)slideOperationViewCell:(XRSlideOperationViewCell *)cell didSelectButtonAtIndex:(NSInteger)index { 158 | NSLog(@"%@", [NSString stringWithFormat:@"点击了第几%ld个按钮", index]); 159 | } 160 | 161 | - (CGSize)slideOperationViewCell:(XRSlideOperationViewCell *)cell sizeAtIndex:(NSInteger)index { 162 | if (index == 0) { 163 | return CGSizeMake(80, 100); 164 | } else if (index == 1) { 165 | return CGSizeMake(60, 100); 166 | } else if (index == 2) { 167 | return CGSizeMake(100, 100); 168 | } 169 | return CGSizeZero; 170 | } 171 | 172 | // 开始滑动的时候调用 173 | - (void)slideOperationViewCellDidBeginSlide:(XRSlideOperationViewCell *)cell { 174 | NSLog(@"---begin---slide"); 175 | } 176 | 177 | @end 178 | -------------------------------------------------------------------------------- /CustomTableVc/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /CustomTableVc/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // CharlesCustomTableViewController 4 | // 5 | // Created by Charles on 16/7/21. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /CustomTableVc/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // CharlesCustomTableViewController 4 | // 5 | // Created by Charles on 16/7/21. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "Demo1ViewController.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | } 21 | 22 | // 点击一下试试 23 | - (IBAction)buttonClick:(UIButton *)sender { 24 | Demo1ViewController *demo1 = [[Demo1ViewController alloc] init]; 25 | [self presentViewController:demo1 animated:YES completion:nil]; 26 | } 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /CustomTableVc/XRSlideTestCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // XRSlideTestCell.h 3 | // CharlesCustomTableViewController 4 | // 5 | // Created by Charles on 16/7/21. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import "XRSlideOperationViewCell.h" 10 | 11 | @interface XRSlideTestCell : XRSlideOperationViewCell 12 | 13 | @property (nonatomic, weak) NSString *name; 14 | @end 15 | -------------------------------------------------------------------------------- /CustomTableVc/XRSlideTestCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // XRSlideTestCell.m 3 | // CharlesCustomTableViewController 4 | // 5 | // Created by Charles on 16/7/21. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import "XRSlideTestCell.h" 10 | 11 | @interface XRSlideTestCell () 12 | @property (nonatomic, weak) UILabel *nameL; 13 | 14 | 15 | @end 16 | 17 | @implementation XRSlideTestCell 18 | 19 | - (UILabel *)nameL { 20 | if (!_nameL) { 21 | UILabel *label = [[UILabel alloc] init]; 22 | [self.cellContentView addSubview:label]; 23 | _nameL = label; 24 | } 25 | return _nameL; 26 | } 27 | 28 | - (void)layoutSubviews { 29 | [super layoutSubviews]; 30 | self.nameL.frame = self.cellContentView.bounds; 31 | } 32 | 33 | - (void)setName:(NSString *)name { 34 | if (name == nil || [name isKindOfClass:[NSNull class]]) { 35 | return ; 36 | } 37 | _name = name.copy; 38 | self.nameL.text = name; 39 | } 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /CustomTableVc/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // TestTableVc 4 | // 5 | // Created by Charles on 16/7/21. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /CustomTableVcTests/CustomTableVcTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // CustomTableVcTests.m 3 | // CustomTableVcTests 4 | // 5 | // Created by Charles on 16/7/21. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CustomTableVcTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation CustomTableVcTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /CustomTableVcTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /CustomTableVcUITests/CustomTableVcUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // CustomTableVcUITests.m 3 | // CustomTableVcUITests 4 | // 5 | // Created by Charles on 16/7/21. 6 | // Copyright © 2016年 Charles. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CustomTableVcUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation CustomTableVcUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /CustomTableVcUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CustomTableViewController 2 | 3 | 1. 封装tableView,带有tableView的控制器、tableViewCell 4 | 5 | 2. 厌烦每次都要写tableView的代理和数据源方法,厌烦每个带有tableView的列表控制器中加入重复代码(例如上拉加载、下拉刷新) 6 | 7 | 3. 封装一层tableView 例如对tableView某一行或者某一分组进行操作的时候不会崩溃(越界处理)、简化了tableView的方法的书写 8 | 9 | 4. 封装一层tableViewCell、直接类方法创建一个可复用的cell,不用在viewDidLoad里面进行注册之类的操作 10 | 11 | 5. 封装一个带有tableView的控制器, 实现诸多变化点,让其可高度化定制。 12 | 13 | 6. 封装一层tableViewHeaderFooterView 同理tableViewCell - - 14 | 15 | 7. 封装一个类似于于微信的会话列表中的可以滑动的cell,可以自定义滑动完成之后的按钮数量,使用方法类似于tableView的代理方法和数据源方法 16 | --------------------------------------------------------------------------------