Skip to content

Instantly share code, notes, and snippets.

@nonamelive
nonamelive / gist:3d3109cc4ca71b6f887e
Created October 13, 2014 18:40
Reference the LaunchImage from Asset Catalog
NSDictionary *dict = @{@"320x480" : @"LaunchImage-700", @"320x568" : @"LaunchImage-700-568h", @"375x667" : @"LaunchImage-800-667h", @"414x736" : @"LaunchImage-800-Portrait-736h"};
NSString *key = [NSString stringWithFormat:@"%dx%d", (int)[UIScreen mainScreen].bounds.size.width, (int)[UIScreen mainScreen].bounds.size.height];
UIImage *launchImage = [UIImage imageNamed:dict[key]];
@nonamelive
nonamelive / DMNavigationBar.h
Last active July 20, 2016 15:17
Prevent UINavigationBar from stealing touches
@interface DMNavigationBar : UINavigationBar
@property (nonatomic, assign) BOOL shouldOnlyReceiveTouchEventsInsideNavigationBar;
@end
@nonamelive
nonamelive / gist:2386f10be807cab78cb2
Created September 16, 2014 18:42
Fix for [UIImage initWithContentsOfFile] on iOS 8 not loading correct images
NSInteger scale = (int)[[UIScreen mainScreen] scale];
UIImage *image = nil;
while (scale > 0 && !image)
{
NSString *fileName = [imageName stringByAppendingString:scale > 1 ? [NSString stringWithFormat:@"@%dx", scale] : @".png"];
NSString *filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"png"];
image = [UIImage imageWithContentsOfFile:filePath];
scale--;
}
@nonamelive
nonamelive / DMNavigationController.m
Last active April 21, 2023 06:56
Prevent UINavigationController from pushing two view controllers at the same time in case of stack inconsistency and crashes
@interface UINavigationController (DMNavigationController)
- (void)didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
@end
@interface DMNavigationController ()
@property (nonatomic, assign) BOOL shouldIgnorePushingViewControllers;
@nonamelive
nonamelive / CollectionViewFloatingHeaderFlowLayout.m
Created May 17, 2013 19:28
A collection view flow layout with floating headers support, compatible with PSTCollectionView. Thanks to @cocotutch! The original answer on StackOverflow can be found at http://stackoverflow.com/questions/13511733/how-to-make-supplementary-view-float-in-uicollectionview-as-section-headers-do-i/13678922#13678922
#import "PSTCollectionView.h"
@implementation CollectionViewFloatingHeaderFlowLayout
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
NSMutableArray *answer = [[super layoutAttributesForElementsInRect:rect] mutableCopy];
PSTCollectionView *const cv = self.collectionView;
CGPoint const contentOffset = cv.contentOffset;