Skip to content

Instantly share code, notes, and snippets.

@MengTo
MengTo / CollectionViewController.m
Last active December 30, 2015 21:19
Scrolls to the cell of your CollectionViewController
- (void)viewDidAppear:(BOOL)animated {
[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:self.indexInt inSection:0]
atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally
animated:YES];
}
@MengTo
MengTo / CollectionViewController.m
Created December 10, 2013 08:10
Sample of a CollectionViewController with 3 sections
@property (nonatomic, strong) NSArray *sections;
- (void)viewDidLoad
{
[super viewDidLoad];
// Cell Sections in Array
self.sections = @[
@{@"identifier": @"firstCell"},
@{@"identifier": @"secondCell"},
@{@"identifier": @"thirdCell"},
@MengTo
MengTo / gist:7887238
Last active December 30, 2015 21:28
Send Data from ViewController to ContainerViewController through Segue's Identifier
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"dialogScene"]) {
self.data = 1;
ViewController *controller = [segue destinationViewController];
controller.data = self.data;
}
}
// In destinationViewController.h
@MengTo
MengTo / gist:7887250
Created December 10, 2013 08:17
Remove Back button text
self.navigationController.navigationBar.topItem.title = @"";
@MengTo
MengTo / gist:7887257
Last active December 30, 2015 21:28
Open link in Safari
NSString *link = [NSString stringWithFormat:@"http://canvaspod.io"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: link]];
@MengTo
MengTo / gist:7887283
Created December 10, 2013 08:22
Hide the Navigation Bar totally, but it still exists if the Sub screens needs it.
// Hide Navigation Bar
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = [UIColor clearColor];
@MengTo
MengTo / gist:7887303
Created December 10, 2013 08:23
The Action button on the Navigation bar gets tinted by default. This is a hack to go to its original colours.
self.buttonLike.image = [[UIImage imageNamed:@"button-like"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
@MengTo
MengTo / gist:7887323
Created December 10, 2013 08:25
The TabBar images are tinted by default. This is a way to use original images.
UITabBarController *tabBarView = (UITabBarController *)self.window.rootViewController;
UITabBarItem *item0 = [tabBarView.tabBar.items objectAtIndex:0];
item0.image = [[UIImage imageNamed:@"icon-chat"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item0.selectedImage = [UIImage imageNamed:@"myImage"];
// In Terminal
vim Podfile
// In Podfile
platform :ios, '7.0'
pod 'Canvas'
// Back to Terminal
pod install
@MengTo
MengTo / gist:11280811
Created April 25, 2014 07:34
Gitignore for Xcode/Cocoapods
# Created by http://www.gitignore.io
### Xcode ###
build
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcworkspace/contents.xcworkspacedata
### Objective-C ###