Skip to content

Instantly share code, notes, and snippets.

View jrturton's full-sized avatar

Richard Turton jrturton

View GitHub Profile
@jrturton
jrturton / UIButton+Insets.m
Created June 27, 2013 13:18
Handy inset adjustments for UIButtons
@implementation UIButton (Insets)
-(void)addSpaceBetweenImageAndText:(CGFloat)space
{
self.titleEdgeInsets = UIEdgeInsetsMake(0.0, space, 0.0, -space);
self.contentEdgeInsets = UIEdgeInsetsMake(0.0, space, 0.0, 2.0 * space);
}
- (void)addSpaceBetweenImageAndText:(CGFloat)space withLeftAndRightPadding:(CGFloat)padding
{
@jrturton
jrturton / Get keyboard frame in local coordinates after receiving notification
Last active September 28, 2016 12:36
Getting the keyboard's frame in local coordinates
CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
keyboardFrame = [self.view.window convertRect:keyboardFrame fromWindow:nil];
keyboardFrame = [self.view convertRect:keyboardFrame fromView:nil];
@jrturton
jrturton / NSString+CurrencyIndicators.m
Created June 7, 2013 10:07
Category for adding currency indicators to NSStrings
@interface NSString (CurrencyIndicators)
-(NSString*)stringByAddingCurrencyIndicator:(NSString*)indicatorCode;
@end
@implementation NSString (CurrencyIndicators)
-(NSString*)stringByAddingCurrencyIndicator:(NSString*)indicatorCode
{
@jrturton
jrturton / GridTableViewController.m
Last active December 18, 2015 03:48
UICollectionView fed by NSFetchedResultsController
#pragma mark - NSFetchedResultsControllerDelegate
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
self.pendingObjectUpdates = [NSMutableArray array];
self.pendingSectionUpdates = [NSMutableArray array];
}
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
@jrturton
jrturton / gist:4690976
Created February 1, 2013 12:16
switch out a screenful of content for another one, in a left or right direction.
-(void)changeArticle:(UIButton*)sender
{
CGFloat multiplier = (sender == self.nextButton) ? 1.0 : -1.0;
// Render to an image and drop in the new version
UIGraphicsBeginImageContextWithOptions(self.articleContainer.frame.size, YES, 0);
CGContextRef c = UIGraphicsGetCurrentContext();
[self.articleContainer.layer renderInContext:c];
UIImage *articleScreenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();