Skip to content

Instantly share code, notes, and snippets.

View romyilano's full-sized avatar
😎
improving

Romy romyilano

😎
improving
View GitHub Profile
@romyilano
romyilano / example.m
Created November 20, 2012 18:58 — forked from henrik/example.m
Locating the keyboard (UIKeyboard) on iOS 4, to e.g. add a custom button.
- (void)someSetupMethod {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:nil];
}
- (void)someTeardownMethod {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
}
@romyilano
romyilano / ios_nav_bar_info_button.m
Created November 20, 2012 18:59 — forked from codeswimmer/ios_nav_bar_info_button.m
iOS: How to add an Info Button to the right button slot in a Navigation Bar
// This is assumed to be inside a UINavigationController
-(void)awakeFromNib
{
// How to turn a NavigationItem's rightBarButtonItem into an Info Button
// First, in your storyboard or xib add a Bar Button Item to the right slot in the navigation bar.
// Then, do this:
UIButton *infoLightButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
infoLightButton.frame = CGRectMake(0.0, 0.0, 25.0, 25.0);
infoLightButton.backgroundColor = [UIColor clearColor];
[infoLightButton addTarget:self action:@selector(showInfo:) forControlEvents:UIControlEventTouchUpInside];
@romyilano
romyilano / reachability
Created November 20, 2012 19:01
Reachability Code
// 1 - nice example from the iPhone for dummies book. Thanks Neal Goldstein! this should be boilerplate reachability
// put in the ApplicationDidFinishLaunchingWithOptions:launchOptions:
// import reachability + make sure that ARC is turned of through -fno-objc-arc
// also import the System configuration framework
// and inside the Reachability class >
// #import <netinet/in.h>
NetworkStatus networkStatus = [[Reachability reachabilityForInternetConnection] currentReachabilityStatus];
if(networkStatus == NotReachable) {
@romyilano
romyilano / animateWithDuration
Created November 20, 2012 19:58
Simple animation in IOS
CGPoint center = CGPointMake(_car.center.x, self.view.frame.origin.y + _car.frame.size.height/2);
[UIView animateWithDuration:3 animations:^{
_car.center =center;
}
completion:^(BOOL finished) {
[self rotate];
}
];
@romyilano
romyilano / viewController.m
Created November 20, 2012 22:45
Swipe Gesture - iOS
-(void)viewDidLoad
{
// gesture recognize
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
swipeGesture.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeGesture];
}
@romyilano
romyilano / blockexample
Created November 25, 2012 17:28
blockExample - from Shawn Welch
// simple demo of a block
// create a new NSString variable demo storing the value hello
NSString *demo = @"Hello";
// define a block with function name helloBlock
void(^helloBlock)(NSString*) = ^(NSString *param) {
NSLog(@"%@,%@", demo, param);
};
@romyilano
romyilano / tutorialFirstLaunch.m
Created December 11, 2012 12:25
how to run something only the 1st time an ios app launches
// http://stackoverflow.com/questions/9450391/show-screen-on-first-launch-only-in-ios
if (![@"1" isEqualToString:[[NSUserDefaults standardUserDefaults]
objectForKey:@"Avalue"]]) {
[[NSUserDefaults standardUserDefaults] setValue:@"1" forKey:@"Avalue"];
[[NSUserDefaults standardUserDefaults] synchronize];
//Action here
@romyilano
romyilano / iphone5Screensize
Created December 17, 2012 00:22
CHeck against the screensize of an iPhone 5 or iPhone 4
// source: http://stackoverflow.com/questions/12395200/how-to-develop-or-migrate-apps-for-iphone-5-screen-resolution/12397309#12397309
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
// code for 4-inch screen
} else {
// code for 3.5-inch screen
}
@romyilano
romyilano / storyboard.m
Created December 17, 2012 00:27
Objective - C - How to launch a storyboard
-(IBAction)homeBtn:(id)sender
{
NSLog(@"Action Button Pressed");
[self.view removeFromSuperview];
UIStoryboard *settingsStoryboard = [UIStoryboard storyboardWithName:@"BentoRock" bundle:nil];
UIViewController *initialSettingsVC = [settingsStoryboard instantiateInitialViewController];
// i'm going to load this view controller modally
initialSettingsVC.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
[self presentViewController:initialSettingsVC
animated:YES
NSMutableArray* reversedMessages = [NSMutableArray arrayWithCapacity:[messages count]];
NSEnumerator* reverseEnumerator = [messages reverseObjectEnumerator];
for (id object in reverseEnumerator)
{
[reversedMessages addObject:Object];
}
// http://stackoverflow.com/questions/7457944/reverse-a-nsarray-worry