Repository: cemolcay/PullToRefreshCoreText Branch: master Commit: 88e5b3ccc56f Files: 26 Total size: 71.9 KB Directory structure: gitextract_kvmoynyz/ ├── LICENSE ├── PullToRefreshCoreText/ │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Base.lproj/ │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ ├── Images.xcassets/ │ │ └── AppIcon.appiconset/ │ │ └── Contents.json │ ├── Info.plist │ ├── PullToRefreshCoreText/ │ │ ├── PullToRefreshCoreTextView.h │ │ ├── PullToRefreshCoreTextView.m │ │ ├── UIScrollView+PullToRefreshCoreText.h │ │ └── UIScrollView+PullToRefreshCoreText.m │ ├── TableViewController.h │ ├── TableViewController.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── PullToRefreshCoreText.podspec ├── PullToRefreshCoreText.xcodeproj/ │ ├── project.pbxproj │ ├── project.xcworkspace/ │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata/ │ │ └── PullToRefreshCoreText.xccheckout │ └── xcuserdata/ │ └── Cem.xcuserdatad/ │ ├── xcdebugger/ │ │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes/ │ ├── PullToRefreshCoreText.xcscheme │ └── xcschememanagement.plist ├── PullToRefreshCoreTextTests/ │ ├── Info.plist │ └── PullToRefreshCoreTextTests.m └── README.md ================================================ FILE CONTENTS ================================================ ================================================ FILE: LICENSE ================================================ Copyright (C) 2014, Cem Olcay Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: PullToRefreshCoreText/AppDelegate.h ================================================ // // AppDelegate.h // PullToRefreshCoreText // // Created by Cem Olcay on 07/10/14. // Copyright (c) 2014 questa. All rights reserved. // #import @interface AppDelegate : UIResponder @property (strong, nonatomic) UIWindow *window; @end ================================================ FILE: PullToRefreshCoreText/AppDelegate.m ================================================ // // AppDelegate.m // PullToRefreshCoreText // // Created by Cem Olcay on 07/10/14. // Copyright (c) 2014 questa. All rights reserved. // #import "AppDelegate.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. return YES; } - (void)applicationWillResignActive:(UIApplication *)application { // 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. // 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. } - (void)applicationDidEnterBackground:(UIApplication *)application { // 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. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - (void)applicationWillEnterForeground:(UIApplication *)application { // 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. } - (void)applicationDidBecomeActive:(UIApplication *)application { // 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. } - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } @end ================================================ FILE: PullToRefreshCoreText/Base.lproj/LaunchScreen.xib ================================================ ================================================ FILE: PullToRefreshCoreText/Base.lproj/Main.storyboard ================================================ ================================================ FILE: PullToRefreshCoreText/Images.xcassets/AppIcon.appiconset/Contents.json ================================================ { "images" : [ { "idiom" : "iphone", "size" : "29x29", "scale" : "2x" }, { "idiom" : "iphone", "size" : "29x29", "scale" : "3x" }, { "idiom" : "iphone", "size" : "40x40", "scale" : "2x" }, { "idiom" : "iphone", "size" : "40x40", "scale" : "3x" }, { "idiom" : "iphone", "size" : "60x60", "scale" : "2x" }, { "idiom" : "iphone", "size" : "60x60", "scale" : "3x" } ], "info" : { "version" : 1, "author" : "xcode" } } ================================================ FILE: PullToRefreshCoreText/Info.plist ================================================ CFBundleDevelopmentRegion en CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier com.questa.$(PRODUCT_NAME:rfc1034identifier) CFBundleInfoDictionaryVersion 6.0 CFBundleName $(PRODUCT_NAME) CFBundlePackageType APPL CFBundleShortVersionString 1.0 CFBundleSignature ???? CFBundleVersion 1 LSRequiresIPhoneOS UILaunchStoryboardName LaunchScreen UIMainStoryboardFile Main UIRequiredDeviceCapabilities armv7 UIStatusBarHidden UIStatusBarStyle UIStatusBarStyleDefault UISupportedInterfaceOrientations UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortraitUpsideDown ================================================ FILE: PullToRefreshCoreText/PullToRefreshCoreText/PullToRefreshCoreTextView.h ================================================ // // PullToRefreshCoreTextView.h // PullToRefreshCoreText // // Created by Cem Olcay on 14/10/14. // Copyright (c) 2014 questa. All rights reserved. // #import #import typedef void(^pullToRefreshAction)(void); typedef NS_ENUM(NSUInteger, PullToRefreshCoreTextStatus) { PullToRefreshCoreTextStatusHidden, PullToRefreshCoreTextStatusDragging, PullToRefreshCoreTextStatusTriggered, }; @interface PullToRefreshCoreTextView : UIView @property (copy) pullToRefreshAction action; @property (nonatomic, assign) PullToRefreshCoreTextStatus status; @property (nonatomic, assign, getter=isLoading) BOOL loading; @property (nonatomic, strong) NSString *pullText; @property (nonatomic, strong) UIColor *pullTextColor; @property (nonatomic, strong) UIFont *pullTextFont; @property (nonatomic, strong) NSString *refreshingText; @property (nonatomic, strong) UIColor *refreshingTextColor; @property (nonatomic, strong) UIFont *refreshingTextFont; @property (nonatomic, weak) UIScrollView *scrollView; @property (nonatomic, assign) CGFloat triggerOffset; @property (nonatomic, assign) CGFloat triggerThreshold; - (instancetype)initWithFrame:(CGRect)frame pullText:(NSString *)pullText pullTextColor:(UIColor *)pullTextColor pullTextFont:(UIFont *)pullTextFont refreshingText:(NSString *)refreshingText refreshingTextColor:(UIColor *)refreshingTextColor refreshingTextFont:(UIFont *)refreshingTextFont action:(pullToRefreshAction)action; - (void)endLoading; @end ================================================ FILE: PullToRefreshCoreText/PullToRefreshCoreText/PullToRefreshCoreTextView.m ================================================ // // PullToRefreshCoreTextView.m // PullToRefreshCoreText // // Created by Cem Olcay on 14/10/14. // Copyright (c) 2014 questa. All rights reserved. // #import "PullToRefreshCoreTextView.h" @implementation NSString (Glyphs) -(UIBezierPath*)bezierPathWithFont:(UIFont*)font { CTFontRef ctFont = CTFontCreateWithName((__bridge CFStringRef)font.fontName, font.pointSize, NULL); NSAttributedString *attributed = [[NSAttributedString alloc] initWithString:self attributes:[NSDictionary dictionaryWithObject:(__bridge id)ctFont forKey:(__bridge NSString*)kCTFontAttributeName]]; CFRelease(ctFont); CGMutablePathRef letters = CGPathCreateMutable(); CTLineRef line = CTLineCreateWithAttributedString((__bridge CFAttributedStringRef)attributed); CFArrayRef runArray = CTLineGetGlyphRuns(line); for (CFIndex runIndex = 0; runIndex < CFArrayGetCount(runArray); runIndex++) { CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(runArray, runIndex); CTFontRef runFont = CFDictionaryGetValue(CTRunGetAttributes(run), kCTFontAttributeName); for (CFIndex runGlyphIndex = 0; runGlyphIndex < CTRunGetGlyphCount(run); runGlyphIndex++) { CFRange thisGlyphRange = CFRangeMake(runGlyphIndex, 1); CGGlyph glyph; CGPoint position; CTRunGetGlyphs(run, thisGlyphRange, &glyph); CTRunGetPositions(run, thisGlyphRange, &position); CGPathRef letter = CTFontCreatePathForGlyph(runFont, glyph, NULL); CGAffineTransform t = CGAffineTransformMakeTranslation(position.x, position.y); CGPathAddPath(letters, &t, letter); CGPathRelease(letter); } } UIBezierPath *path = [UIBezierPath bezierPathWithCGPath:letters]; CGRect boundingBox = CGPathGetBoundingBox(letters); CGPathRelease(letters); CFRelease(line); // The path is upside down (CG coordinate system) [path applyTransform:CGAffineTransformMakeScale(1.0, -1.0)]; [path applyTransform:CGAffineTransformMakeTranslation(0.0, boundingBox.size.height)]; return path; } @end @implementation PullToRefreshCoreTextView #pragma mark - Lifecycle - (instancetype)initWithFrame:(CGRect)frame pullText:(NSString *)pullText pullTextColor:(UIColor *)pullTextColor pullTextFont:(UIFont *)pullTextFont refreshingText:(NSString *)refreshingText refreshingTextColor:(UIColor *)refreshingTextColor refreshingTextFont:(UIFont *)refreshingTextFont action:(pullToRefreshAction)action { if ((self = [super initWithFrame:frame])) { self.pullText = pullText; self.pullTextColor = pullTextColor; self.pullTextFont = pullTextFont; self.refreshingText = refreshingText; self.refreshingTextColor = refreshingTextColor; self.refreshingTextFont = refreshingTextFont; self.action = action; self.status = PullToRefreshCoreTextStatusHidden; self.loading = NO; self.triggerOffset = self.frame.size.height; self.triggerThreshold = self.frame.size.height; } return self; } #pragma mark - Logic - (void)startLoading { [self setLoading:YES]; self.action (); } - (void)endLoading { [self setLoading:NO]; if (self.scrollView.contentInset.top > 0) { [UIView animateWithDuration:0.2 animations:^{ self.scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0); }]; } } - (CAShapeLayer *)pullTextLayer { CAShapeLayer *pull = [CAShapeLayer layer]; [pull setPath:[[self.pullText bezierPathWithFont:self.pullTextFont] CGPath]]; [pull setStrokeColor:[self.pullTextColor CGColor]]; [pull setFillColor:[[UIColor clearColor] CGColor]]; [pull setLineWidth:0.5]; [pull setSpeed:0]; float textSize = [self.pullText sizeWithAttributes:@{NSFontAttributeName:self.pullTextFont}].width; [pull setPosition:CGPointMake(pull.position.x + (self.frame.size.width-textSize)/2, 0)]; CABasicAnimation *textAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; [textAnimation setFromValue:@0]; [textAnimation setToValue:@1]; [textAnimation setDuration:1]; [textAnimation setRemovedOnCompletion:NO]; [pull addAnimation:textAnimation forKey:@"textAnimation"]; return pull; } - (CATextLayer *)refreshingTextLayer { CATextLayer *text = [CATextLayer layer]; [text setFrame:self.bounds]; [text setString:(id)self.refreshingText]; CTFontRef fontRef = CTFontCreateWithName((__bridge CFStringRef)self.refreshingTextFont.fontName, self.refreshingTextFont.pointSize, NULL); [text setFont:fontRef]; CFRelease(fontRef); [text setFontSize:self.refreshingTextFont.pointSize]; [text setForegroundColor:[self.refreshingTextColor CGColor]]; [text setContentsScale:[[UIScreen mainScreen] scale]]; float textSize = [self.refreshingText sizeWithAttributes:@{NSFontAttributeName:self.refreshingTextFont}].width; [text setPosition:CGPointMake(self.frame.size.width-textSize/2, 13)]; //center text in master layer CALayer *maskLayer = [CALayer layer]; maskLayer.backgroundColor = [[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.3] CGColor]; maskLayer.contents = (id)[[UIImage imageNamed:@"Mask.png"] CGImage]; maskLayer.contentsGravity = kCAGravityCenter; maskLayer.frame = CGRectMake(self.frame.size.width * -1, 0.0f, self.frame.size.width * 2, self.frame.size.height); text.mask = maskLayer; CABasicAnimation *maskAnim = [CABasicAnimation animationWithKeyPath:@"position.x"]; maskAnim.byValue = [NSNumber numberWithFloat:self.frame.size.width]; maskAnim.repeatCount = HUGE_VALF; maskAnim.duration = 2.0f; [maskLayer addAnimation:maskAnim forKey:@"slideAnim"]; return text; } #pragma mark - Interaction - (void)scrollViewDidScroll:(UIPanGestureRecognizer *)pan { // Check if the superview's frame width has changed. if (self.superview.bounds.size.width != self.frame.size.width) { // Update our frame with the new width. CGRect newFrame = self.frame; newFrame.size.width = self.superview.bounds.size.width; self.frame = newFrame; // Update the layers. [self setLoading:self.isLoading]; } if (pan.state == UIGestureRecognizerStateChanged) { if (self.isLoading) return; CGFloat offset = self.scrollView.contentOffset.y + self.triggerThreshold; if (offset <= 0) { //animate pull text CGFloat fractionDragged = -offset/self.triggerOffset; [(CALayer *)[self.layer.sublayers firstObject] setTimeOffset:MIN(1, fractionDragged)]; //update state if (fractionDragged >= 1) { self.status = PullToRefreshCoreTextStatusTriggered; } else { self.status = PullToRefreshCoreTextStatusDragging; } } else { self.status = PullToRefreshCoreTextStatusHidden; } } else if (pan.state == UIGestureRecognizerStateEnded || pan.state == UIGestureRecognizerStateCancelled) { if (self.status == PullToRefreshCoreTextStatusTriggered) { [self startLoading]; [UIView animateWithDuration:0.2 animations:^{ [self.scrollView setContentInset:UIEdgeInsetsMake(self.triggerOffset + self.triggerThreshold, 0, 0, 0)]; }]; } else { [(CALayer *)[self.layer.sublayers firstObject] setTimeOffset:0]; } } } #pragma mark - Properties - (void)setScrollView:(UIScrollView *)scrollView { _scrollView = scrollView; [self.scrollView.panGestureRecognizer addTarget:self action:@selector(scrollViewDidScroll:)]; } - (void)setLoading:(BOOL)loading { _loading = loading; self.layer.sublayers = nil; if (loading) { [self.layer addSublayer:[self refreshingTextLayer]]; } else { [self.layer addSublayer:[self pullTextLayer]]; } } @end ================================================ FILE: PullToRefreshCoreText/PullToRefreshCoreText/UIScrollView+PullToRefreshCoreText.h ================================================ // // UIScrollView+PullToRefreshCoreText.h // PullToRefreshCoreText // // Created by Cem Olcay on 07/10/14. // Copyright (c) 2014 questa. All rights reserved. // #import #import "PullToRefreshCoreTextView.h" #define DefaultTextColor [UIColor blackColor] #define DefaultTextFont [UIFont fontWithName:@"HelveticaNeue-UltraLight" size:30] @interface UIScrollView (PullToRefreshCoreText) @property (nonatomic, strong) PullToRefreshCoreTextView *pullToRefreshView; - (void)addPullToRefreshWithPullText:(NSString *)pullText action:(pullToRefreshAction)action; - (void)addPullToRefreshWithPullText:(NSString *)pullText refreshingText:(NSString *)refreshingText action:(pullToRefreshAction)action; - (void)addPullToRefreshWithPullText:(NSString *)pullText font:(UIFont *)font action:(pullToRefreshAction)action; - (void)addPullToRefreshWithPullText:(NSString *)pullText refreshingText:(NSString *)refreshingText font:(UIFont *)font action:(pullToRefreshAction)action; - (void)addPullToRefreshWithPullText:(NSString *)pullText pullTextColor:(UIColor *)pullTextColor refreshingText:(NSString *)refreshingText refreshingTextColor:(UIColor *)refreshingTextColor font:(UIFont *)font action:(pullToRefreshAction)action; - (void)addPullToRefreshWithPullText:(NSString *)pullText pullTextColor:(UIColor *)pullTextColor pullTextFont:(UIFont *)pullTextFont refreshingText:(NSString *)refreshingText refreshingTextColor:(UIColor *)refreshingTextColor refreshingTextFont:(UIFont *)refreshingTextFont action:(pullToRefreshAction)action; - (void)finishLoading; @end ================================================ FILE: PullToRefreshCoreText/PullToRefreshCoreText/UIScrollView+PullToRefreshCoreText.m ================================================ // // UIScrollView+PullToRefreshCoreText.m // PullToRefreshCoreText // // Created by Cem Olcay on 07/10/14. // Copyright (c) 2014 questa. All rights reserved. // #import "UIScrollView+PullToRefreshCoreText.h" #import @implementation UIScrollView (PullToRefreshCoreText) #pragma mark - Lifecycle - (void)addPullToRefreshWithPullText:(NSString *)pullText action:(pullToRefreshAction)action { [self addPullToRefreshWithPullText:pullText pullTextColor:DefaultTextColor pullTextFont:DefaultTextFont refreshingText:pullText refreshingTextColor:DefaultTextColor refreshingTextFont:DefaultTextFont action:action]; } - (void)addPullToRefreshWithPullText:(NSString *)pullText refreshingText:(NSString *)refreshingText action:(pullToRefreshAction)action { [self addPullToRefreshWithPullText:pullText pullTextColor:DefaultTextColor pullTextFont:DefaultTextFont refreshingText:refreshingText refreshingTextColor:DefaultTextColor refreshingTextFont:DefaultTextFont action:action]; } - (void)addPullToRefreshWithPullText:(NSString *)pullText font:(UIFont *)font action:(pullToRefreshAction)action { [self addPullToRefreshWithPullText:pullText pullTextColor:DefaultTextColor pullTextFont:font refreshingText:pullText refreshingTextColor:DefaultTextColor refreshingTextFont:font action:action]; } - (void)addPullToRefreshWithPullText:(NSString *)pullText refreshingText:(NSString *)refreshingText font:(UIFont *)font action:(pullToRefreshAction)action { [self addPullToRefreshWithPullText:pullText pullTextColor:DefaultTextColor pullTextFont:DefaultTextFont refreshingText:pullText refreshingTextColor:DefaultTextColor refreshingTextFont:DefaultTextFont action:action]; } - (void)addPullToRefreshWithPullText:(NSString *)pullText pullTextColor:(UIColor *)pullTextColor refreshingText:(NSString *)refreshingText refreshingTextColor:(UIColor *)refreshingTextColor font:(UIFont *)font action:(pullToRefreshAction)action { [self addPullToRefreshWithPullText:pullText pullTextColor:pullTextColor pullTextFont:font refreshingText:refreshingText refreshingTextColor:refreshingTextColor refreshingTextFont:font action:action]; } - (void)addPullToRefreshWithPullText:(NSString *)pullText pullTextColor:(UIColor *)pullTextColor pullTextFont:(UIFont *)pullTextFont refreshingText:(NSString *)refreshingText refreshingTextColor:(UIColor *)refreshingTextColor refreshingTextFont:(UIFont *)refreshingTextFont action:(pullToRefreshAction)action { if (self.pullToRefreshView) return; float ptrH = [self labelHeightForString:pullText labelWidth:self.bounds.size.width andFont:pullTextFont]; CGRect ptrRect = CGRectMake(0, -ptrH, self.bounds.size.width, ptrH); self.pullToRefreshView = [[PullToRefreshCoreTextView alloc] initWithFrame:ptrRect pullText:pullText pullTextColor:pullTextColor pullTextFont:pullTextFont refreshingText:refreshingText refreshingTextColor:refreshingTextColor refreshingTextFont:refreshingTextFont action:action]; [self.pullToRefreshView setScrollView:self]; [self addSubview:self.pullToRefreshView]; } #pragma mark - Loading - (void)finishLoading { [self.pullToRefreshView endLoading]; } #pragma mark - Utils - (CGFloat)labelHeightForString:(NSString*)string labelWidth:(float)width andFont:(UIFont*)font { NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:string attributes:@{NSFontAttributeName: font}]; CGRect rect = [attributedText boundingRectWithSize:(CGSize){width, CGFLOAT_MAX} options:NSStringDrawingUsesLineFragmentOrigin context:nil]; return rect.size.height; } #pragma mark - Properties - (void)setPullToRefreshView:(PullToRefreshCoreTextView *)pullToRefreshView { objc_setAssociatedObject(self, @selector(pullToRefreshView), pullToRefreshView, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } - (PullToRefreshCoreTextView *)pullToRefreshView { return objc_getAssociatedObject(self, @selector(pullToRefreshView)); } @end ================================================ FILE: PullToRefreshCoreText/TableViewController.h ================================================ // // TableViewController.h // PullToRefreshCoreText // // Created by Codi Bonney on 12/3/15. // Copyright © 2015 questa. All rights reserved. // #import @interface TableViewController : UITableViewController @end ================================================ FILE: PullToRefreshCoreText/TableViewController.m ================================================ // // TableViewController.m // PullToRefreshCoreText // // Created by Codi Bonney on 12/3/15. // Copyright © 2015 questa. All rights reserved. // #import "TableViewController.h" #import "UIScrollView+PullToRefreshCoreText.h" static NSString* const KCellIdentifier = @"PTRCTTableCell"; @interface TableViewController () @property (nonatomic) NSMutableArray* datasource; @end @implementation TableViewController - (void)viewDidLoad { [super viewDidLoad]; self.datasource = [NSMutableArray new]; // TODO: add support for UIRectEdgeAll self.edgesForExtendedLayout = UIRectEdgeNone; //add pull to refresh __weak typeof(self) weakSelf = self; [self.tableView addPullToRefreshWithPullText:@"Pull To Refresh" pullTextColor:[UIColor blackColor] pullTextFont:DefaultTextFont refreshingText:@"Refreshing" refreshingTextColor:[UIColor blueColor] refreshingTextFont:DefaultTextFont action:^{ [weakSelf loadItems]; }]; //add some items to scroll view for (int i = 0; i < 2; i++) { [self addNewItem]; } } - (void)loadItems { __weak typeof(UIScrollView *) weakScrollView = self.tableView; __weak typeof(self) weakSelf = self; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [weakSelf addNewItem]; [weakScrollView finishLoading]; }); } - (void)addNewItem { [self.datasource addObject:[self randomColor]]; [self.tableView reloadData]; } - (UIColor *)randomColor { CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0 CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black return [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1]; } #pragma mark - UITableView DataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.datasource.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:KCellIdentifier]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:KCellIdentifier]; } cell.textLabel.text = @(indexPath.row+1).stringValue; cell.backgroundColor = self.datasource[indexPath.row]; return cell; } @end ================================================ FILE: PullToRefreshCoreText/ViewController.h ================================================ // // ViewController.h // PullToRefreshCoreText // // Created by Cem Olcay on 07/10/14. // Copyright (c) 2014 questa. All rights reserved. // #import @interface ViewController : UIViewController @end ================================================ FILE: PullToRefreshCoreText/ViewController.m ================================================ // // ViewController.m // PullToRefreshCoreText // // Created by Cem Olcay on 07/10/14. // Copyright (c) 2014 questa. All rights reserved. // #import "ViewController.h" #import "UIScrollView+PullToRefreshCoreText.h" @interface ViewController () @property (nonatomic, strong) UIScrollView *scrollView; @property (nonatomic, assign) CGFloat contentHeight; @property (nonatomic, assign) NSInteger itemCount; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; [self setupScrollView]; } #pragma mark - UIScrollView - (void)setupScrollView { self.contentHeight = 10; self.itemCount = 0; //Create ScrollView self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame]; [self.scrollView setContentSize:CGSizeMake(self.view.frame.size.width, self.scrollView.frame.size.height + 1)]; [self.view addSubview:self.scrollView]; //add pull to refresh __weak typeof(self) weakSelf = self; [self.scrollView addPullToRefreshWithPullText:@"Pull To Refresh" pullTextColor:[UIColor blackColor] pullTextFont:DefaultTextFont refreshingText:@"Refreshing" refreshingTextColor:[UIColor blueColor] refreshingTextFont:DefaultTextFont action:^{ [weakSelf loadItems]; }]; //add some items to scroll view for (int i = 0; i < 2; i++) { [self addNewItem]; } } - (void)loadItems { __weak typeof(UIScrollView *) weakScrollView = self.scrollView; __weak typeof(self) weakSelf = self; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [weakSelf addNewItem]; [weakScrollView finishLoading]; }); } - (void)addNewItem { [self.scrollView addSubview:[self item]]; if (self.scrollView.contentSize.height < self.contentHeight) [self.scrollView setContentSize:CGSizeMake(self.scrollView.contentSize.width, self.contentHeight)]; } - (UILabel *)item { UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(10, self.contentHeight, self.view.frame.size.width - 20, 150)]; [lbl setText:[NSString stringWithFormat:@"item %lu", self.itemCount++]]; [lbl setTextAlignment:NSTextAlignmentCenter]; [lbl setBackgroundColor:[self randomColor]]; [lbl setFont:DefaultTextFont]; self.contentHeight += 160; return lbl; } - (UIColor *)randomColor { CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0 CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black return [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1]; } @end ================================================ FILE: PullToRefreshCoreText/main.m ================================================ // // main.m // PullToRefreshCoreText // // Created by Cem Olcay on 07/10/14. // Copyright (c) 2014 questa. All rights reserved. // #import #import "AppDelegate.h" int main(int argc, char * argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } } ================================================ FILE: PullToRefreshCoreText.podspec ================================================ # # Be sure to run `pod spec lint PullToRefreshCoreText.podspec' to ensure this is a # valid spec and to remove all comments including this before submitting the spec. # # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ # Pod::Spec.new do |s| # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # # # These will help people to find your library, and whilst it # can feel like a chore to fill in it's definitely to your advantage. The # summary should be tweet-length, and the description more in depth. # s.name = "PullToRefreshCoreText" s.version = "0.2" s.summary = "PullToRefresh extension for all UIScrollView type classes with animated text drawing style " s.description = <<-DESC https://github.com/cemolcay/PullToRefreshCoreText/blob/master/README.md DESC s.homepage = "https://github.com/cemolcay/PullToRefreshCoreText" # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif" # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # # # Licensing your code is important. See http://choosealicense.com for more info. # CocoaPods will detect a license file if there is a named LICENSE* # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'. # s.license = "MIT" # s.license = { :type => "MIT", :file => "FILE_LICENSE" } # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # # # Specify the authors of the library, with email addresses. Email addresses # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also # accepts just a name if you'd rather not provide an email address. # # Specify a social_media_url where others can refer to, for example a twitter # profile URL. # s.author = { "cemolcay" => "ccemolcay@gmail.com" } # Or just: s.author = "cemolcay" # s.authors = { "cemolcay" => "ccemolcay@gmail.com" } # s.social_media_url = "http://twitter.com/cemolcay" # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # # # If this Pod runs only on iOS or OS X, then specify the platform and # the deployment target. You can optionally include the target after the platform. # # s.platform = :ios s.platform = :ios, "7.0" # When using multiple platforms # s.ios.deployment_target = "5.0" # s.osx.deployment_target = "10.7" # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # # # Specify the location from where the source should be retrieved. # Supports git, hg, bzr, svn and HTTP. # s.source = { :git => "https://github.com/cemolcay/PullToRefreshCoreText.git", :tag => "v0.2" } # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # # # CocoaPods is smart about how it includes source code. For source files # giving a folder will include any h, m, mm, c & cpp files. For header # files it will include any header in the folder. # Not including the public_header_files will make all headers public. # s.source_files = "PullToRefreshCoreText/PullToRefreshCoreText/*.{h,m}" # s.public_header_files = "Classes/**/*.h" # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # # # A list of resources included with the Pod. These are copied into the # target bundle with a build phase script. Anything else will be cleaned. # You can preserve files from being cleaned, please don't preserve # non-essential files like tests, examples and documentation. # # s.resource = "icon.png" s.resources = "PullToRefreshCoreText/PullToRefreshCoreText/*.png" # s.preserve_paths = "FilesToSave", "MoreFilesToSave" # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # # # Link your library with frameworks, or libraries. Libraries do not include # the lib prefix of their name. # s.framework = "CoreText" # s.frameworks = "SomeFramework", "AnotherFramework" # s.library = "iconv" # s.libraries = "iconv", "xml2" # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # # # If your library depends on compiler flags you can set them in the xcconfig hash # where they will only apply to your library. If you depend on other Podspecs # you can include multiple dependencies to ensure it works. s.requires_arc = true # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } # s.dependency "JSONKit", "~> 1.4" end ================================================ FILE: PullToRefreshCoreText.xcodeproj/project.pbxproj ================================================ // !$*UTF8*$! { archiveVersion = 1; classes = { }; objectVersion = 46; objects = { /* Begin PBXBuildFile section */ B29BC27919E4178E00365B69 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = B29BC27819E4178E00365B69 /* main.m */; }; B29BC27C19E4178E00365B69 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = B29BC27B19E4178E00365B69 /* AppDelegate.m */; }; B29BC27F19E4178E00365B69 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B29BC27E19E4178E00365B69 /* ViewController.m */; }; B29BC28219E4178E00365B69 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B29BC28019E4178E00365B69 /* Main.storyboard */; }; B29BC28419E4178E00365B69 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B29BC28319E4178E00365B69 /* Images.xcassets */; }; B29BC28719E4178E00365B69 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = B29BC28519E4178E00365B69 /* LaunchScreen.xib */; }; B29BC29319E4178E00365B69 /* PullToRefreshCoreTextTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B29BC29219E4178E00365B69 /* PullToRefreshCoreTextTests.m */; }; B2D4613119F006ED00C6B60A /* Mask.png in Resources */ = {isa = PBXBuildFile; fileRef = B2D4612C19F006ED00C6B60A /* Mask.png */; }; B2D4613219F006ED00C6B60A /* PullToRefreshCoreTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = B2D4612E19F006ED00C6B60A /* PullToRefreshCoreTextView.m */; }; B2D4613319F006ED00C6B60A /* UIScrollView+PullToRefreshCoreText.m in Sources */ = {isa = PBXBuildFile; fileRef = B2D4613019F006ED00C6B60A /* UIScrollView+PullToRefreshCoreText.m */; }; C00613BA1C10F7DC00E38B9E /* TableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C00613B91C10F7DC00E38B9E /* TableViewController.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ B29BC28D19E4178E00365B69 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = B29BC26B19E4178E00365B69 /* Project object */; proxyType = 1; remoteGlobalIDString = B29BC27219E4178E00365B69; remoteInfo = PullToRefreshCoreText; }; /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ B29BC27319E4178E00365B69 /* PullToRefreshCoreText.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PullToRefreshCoreText.app; sourceTree = BUILT_PRODUCTS_DIR; }; B29BC27719E4178E00365B69 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; B29BC27819E4178E00365B69 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; B29BC27A19E4178E00365B69 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; B29BC27B19E4178E00365B69 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; B29BC27D19E4178E00365B69 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; B29BC27E19E4178E00365B69 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; B29BC28119E4178E00365B69 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; B29BC28319E4178E00365B69 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; B29BC28619E4178E00365B69 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; B29BC28C19E4178E00365B69 /* PullToRefreshCoreTextTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PullToRefreshCoreTextTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; B29BC29119E4178E00365B69 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; B29BC29219E4178E00365B69 /* PullToRefreshCoreTextTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PullToRefreshCoreTextTests.m; sourceTree = ""; }; B2D4612C19F006ED00C6B60A /* Mask.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Mask.png; sourceTree = ""; }; B2D4612D19F006ED00C6B60A /* PullToRefreshCoreTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PullToRefreshCoreTextView.h; sourceTree = ""; }; B2D4612E19F006ED00C6B60A /* PullToRefreshCoreTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PullToRefreshCoreTextView.m; sourceTree = ""; }; B2D4612F19F006ED00C6B60A /* UIScrollView+PullToRefreshCoreText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIScrollView+PullToRefreshCoreText.h"; sourceTree = ""; }; B2D4613019F006ED00C6B60A /* UIScrollView+PullToRefreshCoreText.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIScrollView+PullToRefreshCoreText.m"; sourceTree = ""; }; C00613B81C10F7DC00E38B9E /* TableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TableViewController.h; sourceTree = ""; }; C00613B91C10F7DC00E38B9E /* TableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TableViewController.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ B29BC27019E4178E00365B69 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; B29BC28919E4178E00365B69 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ B29BC26A19E4178E00365B69 = { isa = PBXGroup; children = ( B29BC27519E4178E00365B69 /* PullToRefreshCoreText */, B29BC28F19E4178E00365B69 /* PullToRefreshCoreTextTests */, B29BC27419E4178E00365B69 /* Products */, ); sourceTree = ""; }; B29BC27419E4178E00365B69 /* Products */ = { isa = PBXGroup; children = ( B29BC27319E4178E00365B69 /* PullToRefreshCoreText.app */, B29BC28C19E4178E00365B69 /* PullToRefreshCoreTextTests.xctest */, ); name = Products; sourceTree = ""; }; B29BC27519E4178E00365B69 /* PullToRefreshCoreText */ = { isa = PBXGroup; children = ( B2D4612B19F006ED00C6B60A /* PullToRefreshCoreText */, B29BC27A19E4178E00365B69 /* AppDelegate.h */, B29BC27B19E4178E00365B69 /* AppDelegate.m */, B29BC27D19E4178E00365B69 /* ViewController.h */, B29BC27E19E4178E00365B69 /* ViewController.m */, C00613B81C10F7DC00E38B9E /* TableViewController.h */, C00613B91C10F7DC00E38B9E /* TableViewController.m */, B29BC28019E4178E00365B69 /* Main.storyboard */, B29BC28319E4178E00365B69 /* Images.xcassets */, B29BC28519E4178E00365B69 /* LaunchScreen.xib */, B29BC27619E4178E00365B69 /* Supporting Files */, ); path = PullToRefreshCoreText; sourceTree = ""; }; B29BC27619E4178E00365B69 /* Supporting Files */ = { isa = PBXGroup; children = ( B29BC27719E4178E00365B69 /* Info.plist */, B29BC27819E4178E00365B69 /* main.m */, ); name = "Supporting Files"; sourceTree = ""; }; B29BC28F19E4178E00365B69 /* PullToRefreshCoreTextTests */ = { isa = PBXGroup; children = ( B29BC29219E4178E00365B69 /* PullToRefreshCoreTextTests.m */, B29BC29019E4178E00365B69 /* Supporting Files */, ); path = PullToRefreshCoreTextTests; sourceTree = ""; }; B29BC29019E4178E00365B69 /* Supporting Files */ = { isa = PBXGroup; children = ( B29BC29119E4178E00365B69 /* Info.plist */, ); name = "Supporting Files"; sourceTree = ""; }; B2D4612B19F006ED00C6B60A /* PullToRefreshCoreText */ = { isa = PBXGroup; children = ( B2D4612C19F006ED00C6B60A /* Mask.png */, B2D4612D19F006ED00C6B60A /* PullToRefreshCoreTextView.h */, B2D4612E19F006ED00C6B60A /* PullToRefreshCoreTextView.m */, B2D4612F19F006ED00C6B60A /* UIScrollView+PullToRefreshCoreText.h */, B2D4613019F006ED00C6B60A /* UIScrollView+PullToRefreshCoreText.m */, ); path = PullToRefreshCoreText; sourceTree = ""; }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ B29BC27219E4178E00365B69 /* PullToRefreshCoreText */ = { isa = PBXNativeTarget; buildConfigurationList = B29BC29619E4178E00365B69 /* Build configuration list for PBXNativeTarget "PullToRefreshCoreText" */; buildPhases = ( B29BC26F19E4178E00365B69 /* Sources */, B29BC27019E4178E00365B69 /* Frameworks */, B29BC27119E4178E00365B69 /* Resources */, ); buildRules = ( ); dependencies = ( ); name = PullToRefreshCoreText; productName = PullToRefreshCoreText; productReference = B29BC27319E4178E00365B69 /* PullToRefreshCoreText.app */; productType = "com.apple.product-type.application"; }; B29BC28B19E4178E00365B69 /* PullToRefreshCoreTextTests */ = { isa = PBXNativeTarget; buildConfigurationList = B29BC29919E4178E00365B69 /* Build configuration list for PBXNativeTarget "PullToRefreshCoreTextTests" */; buildPhases = ( B29BC28819E4178E00365B69 /* Sources */, B29BC28919E4178E00365B69 /* Frameworks */, B29BC28A19E4178E00365B69 /* Resources */, ); buildRules = ( ); dependencies = ( B29BC28E19E4178E00365B69 /* PBXTargetDependency */, ); name = PullToRefreshCoreTextTests; productName = PullToRefreshCoreTextTests; productReference = B29BC28C19E4178E00365B69 /* PullToRefreshCoreTextTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ B29BC26B19E4178E00365B69 /* Project object */ = { isa = PBXProject; attributes = { LastUpgradeCheck = 0600; ORGANIZATIONNAME = questa; TargetAttributes = { B29BC27219E4178E00365B69 = { CreatedOnToolsVersion = 6.0.1; }; B29BC28B19E4178E00365B69 = { CreatedOnToolsVersion = 6.0.1; TestTargetID = B29BC27219E4178E00365B69; }; }; }; buildConfigurationList = B29BC26E19E4178E00365B69 /* Build configuration list for PBXProject "PullToRefreshCoreText" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( en, Base, ); mainGroup = B29BC26A19E4178E00365B69; productRefGroup = B29BC27419E4178E00365B69 /* Products */; projectDirPath = ""; projectRoot = ""; targets = ( B29BC27219E4178E00365B69 /* PullToRefreshCoreText */, B29BC28B19E4178E00365B69 /* PullToRefreshCoreTextTests */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ B29BC27119E4178E00365B69 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( B29BC28219E4178E00365B69 /* Main.storyboard in Resources */, B29BC28719E4178E00365B69 /* LaunchScreen.xib in Resources */, B29BC28419E4178E00365B69 /* Images.xcassets in Resources */, B2D4613119F006ED00C6B60A /* Mask.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; B29BC28A19E4178E00365B69 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ B29BC26F19E4178E00365B69 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( B29BC27F19E4178E00365B69 /* ViewController.m in Sources */, C00613BA1C10F7DC00E38B9E /* TableViewController.m in Sources */, B29BC27C19E4178E00365B69 /* AppDelegate.m in Sources */, B2D4613219F006ED00C6B60A /* PullToRefreshCoreTextView.m in Sources */, B2D4613319F006ED00C6B60A /* UIScrollView+PullToRefreshCoreText.m in Sources */, B29BC27919E4178E00365B69 /* main.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; B29BC28819E4178E00365B69 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( B29BC29319E4178E00365B69 /* PullToRefreshCoreTextTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ B29BC28E19E4178E00365B69 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = B29BC27219E4178E00365B69 /* PullToRefreshCoreText */; targetProxy = B29BC28D19E4178E00365B69 /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ B29BC28019E4178E00365B69 /* Main.storyboard */ = { isa = PBXVariantGroup; children = ( B29BC28119E4178E00365B69 /* Base */, ); name = Main.storyboard; sourceTree = ""; }; B29BC28519E4178E00365B69 /* LaunchScreen.xib */ = { isa = PBXVariantGroup; children = ( B29BC28619E4178E00365B69 /* Base */, ); name = LaunchScreen.xib; sourceTree = ""; }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ B29BC29419E4178E00365B69 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; }; name = Debug; }; B29BC29519E4178E00365B69 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = YES; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; name = Release; }; B29BC29719E4178E00365B69 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = PullToRefreshCoreText/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; }; B29BC29819E4178E00365B69 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = PullToRefreshCoreText/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; }; B29BC29A19E4178E00365B69 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; FRAMEWORK_SEARCH_PATHS = ( "$(SDKROOT)/Developer/Library/Frameworks", "$(inherited)", ); GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", ); INFOPLIST_FILE = PullToRefreshCoreTextTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PullToRefreshCoreText.app/PullToRefreshCoreText"; }; name = Debug; }; B29BC29B19E4178E00365B69 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; FRAMEWORK_SEARCH_PATHS = ( "$(SDKROOT)/Developer/Library/Frameworks", "$(inherited)", ); INFOPLIST_FILE = PullToRefreshCoreTextTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PullToRefreshCoreText.app/PullToRefreshCoreText"; }; name = Release; }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ B29BC26E19E4178E00365B69 /* Build configuration list for PBXProject "PullToRefreshCoreText" */ = { isa = XCConfigurationList; buildConfigurations = ( B29BC29419E4178E00365B69 /* Debug */, B29BC29519E4178E00365B69 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; B29BC29619E4178E00365B69 /* Build configuration list for PBXNativeTarget "PullToRefreshCoreText" */ = { isa = XCConfigurationList; buildConfigurations = ( B29BC29719E4178E00365B69 /* Debug */, B29BC29819E4178E00365B69 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; B29BC29919E4178E00365B69 /* Build configuration list for PBXNativeTarget "PullToRefreshCoreTextTests" */ = { isa = XCConfigurationList; buildConfigurations = ( B29BC29A19E4178E00365B69 /* Debug */, B29BC29B19E4178E00365B69 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; rootObject = B29BC26B19E4178E00365B69 /* Project object */; } ================================================ FILE: PullToRefreshCoreText.xcodeproj/project.xcworkspace/contents.xcworkspacedata ================================================ ================================================ FILE: PullToRefreshCoreText.xcodeproj/project.xcworkspace/xcshareddata/PullToRefreshCoreText.xccheckout ================================================ IDESourceControlProjectFavoriteDictionaryKey IDESourceControlProjectIdentifier C6F89E8B-DE7C-40DA-96D9-07D64821BF19 IDESourceControlProjectName PullToRefreshCoreText IDESourceControlProjectOriginsDictionary 51D0BD135080145A51AAFC376EF45758245B9CE6 https://github.com/cemolcay/PullToRefreshCoreText.git IDESourceControlProjectPath PullToRefreshCoreText.xcodeproj IDESourceControlProjectRelativeInstallPathDictionary 51D0BD135080145A51AAFC376EF45758245B9CE6 ../.. IDESourceControlProjectURL https://github.com/cemolcay/PullToRefreshCoreText.git IDESourceControlProjectVersion 111 IDESourceControlProjectWCCIdentifier 51D0BD135080145A51AAFC376EF45758245B9CE6 IDESourceControlProjectWCConfigurations IDESourceControlRepositoryExtensionIdentifierKey public.vcs.git IDESourceControlWCCIdentifierKey 51D0BD135080145A51AAFC376EF45758245B9CE6 IDESourceControlWCCName PullToRefreshCoreText ================================================ FILE: PullToRefreshCoreText.xcodeproj/xcuserdata/Cem.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist ================================================ ================================================ FILE: PullToRefreshCoreText.xcodeproj/xcuserdata/Cem.xcuserdatad/xcschemes/PullToRefreshCoreText.xcscheme ================================================ ================================================ FILE: PullToRefreshCoreText.xcodeproj/xcuserdata/Cem.xcuserdatad/xcschemes/xcschememanagement.plist ================================================ SchemeUserState PullToRefreshCoreText.xcscheme orderHint 0 SuppressBuildableAutocreation B29BC27219E4178E00365B69 primary B29BC28B19E4178E00365B69 primary ================================================ FILE: PullToRefreshCoreTextTests/Info.plist ================================================ CFBundleDevelopmentRegion en CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier com.questa.$(PRODUCT_NAME:rfc1034identifier) CFBundleInfoDictionaryVersion 6.0 CFBundleName $(PRODUCT_NAME) CFBundlePackageType BNDL CFBundleShortVersionString 1.0 CFBundleSignature ???? CFBundleVersion 1 ================================================ FILE: PullToRefreshCoreTextTests/PullToRefreshCoreTextTests.m ================================================ // // PullToRefreshCoreTextTests.m // PullToRefreshCoreTextTests // // Created by Cem Olcay on 07/10/14. // Copyright (c) 2014 questa. All rights reserved. // #import #import @interface PullToRefreshCoreTextTests : XCTestCase @end @implementation PullToRefreshCoreTextTests - (void)setUp { [super setUp]; // Put setup code here. This method is called before the invocation of each test method in the class. } - (void)tearDown { // Put teardown code here. This method is called after the invocation of each test method in the class. [super tearDown]; } - (void)testExample { // This is an example of a functional test case. XCTAssert(YES, @"Pass"); } - (void)testPerformanceExample { // This is an example of a performance test case. [self measureBlock:^{ // Put the code you want to measure the time of here. }]; } @end ================================================ FILE: README.md ================================================ PullToRefreshCoreText ===================== PullToRefresh extension for all UIScrollView type classes with animated text drawing style
Demo ---- ![alt tag](https://raw.githubusercontent.com/cemolcay/PullToRefreshCoreText/master/demo.gif) Install ------- **Manual** Copy the files in the folder named PullToRefreshCoreText to your project. Import the "UIScrollView+PullToRefreshCoreText.h" **Cocoapods** ``` source 'https://github.com/CocoaPods/Specs.git' pod 'PullToRefreshCoreText', '~> 0.2' ``` Usage ----- - (void)addPullToRefreshWithPullText:(NSString *)pullText pullTextColor:(UIColor *)pullTextColor pullTextFont:(UIFont *)pullTextFont refreshingText:(NSString *)refreshingText refreshingTextColor:(UIColor *)refreshingTextColor refreshingTextFont:(UIFont *)refreshingTextFont action:(pullToRefreshAction)action; It has 2 main texts, pulling and refreshing.
Init function has parameters for creating this texts with its strings, text colors and fonts.
Last parameter is the block function where loading code goes to.
Alternatively I added some other init methods if you want to use same texts or fonts etc.
- (void)addPullToRefreshWithPullText:(NSString *)pullText action:(pullToRefreshAction)action; - (void)addPullToRefreshWithPullText:(NSString *)pullText refreshingText:(NSString *)refreshingText action:(pullToRefreshAction)action; - (void)addPullToRefreshWithPullText:(NSString *)pullText font:(UIFont *)font action:(pullToRefreshAction)action; - (void)addPullToRefreshWithPullText:(NSString *)pullText refreshingText:(NSString *)refreshingText font:(UIFont *)font action:(pullToRefreshAction)action; - (void)addPullToRefreshWithPullText:(NSString *)pullText pullTextColor:(UIColor *)pullTextColor refreshingText:(NSString *)refreshingText refreshingTextColor:(UIColor *)refreshingTextColor font:(UIFont *)font action:(pullToRefreshAction)action; Implementation -------------- //Create ScrollView self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame]; [self.scrollView setContentSize:CGSizeMake(self.view.frame.size.width, self.scrollView.frame.size.height + 1)]; [self.view addSubview:self.scrollView]; //add pull to refresh __weak typeof(self) weakSelf = self; [self.scrollView addPullToRefreshWithPullText:@"Pull To Refresh" pullTextColor:[UIColor blackColor] pullTextFont:DefaultTextFont refreshingText:@"Refreshing" refreshingTextColor:[UIColor blueColor] refreshingTextFont:DefaultTextFont action:^{ [weakSelf loadItems]; }]; One last thing: you should call the `[scrollView finishLoading]` method after the load finishes.
Otherwise you stuck in refreshing state always. Credits ======= Blogs and codes I used for creating this
https://github.com/jrturton/NSString-Glyphs
http://www.codeproject.com/Articles/109729/Low-level-text-rendering
http://ronnqvi.st/controlling-animation-timing/