Skip to content

Instantly share code, notes, and snippets.

@inailuy
inailuy / Custom TableViewCell
Last active December 12, 2015 01:48
creating custom tableview cells
// Registering Cell eg: -viewDidLoad
[self.tableView registerNib:[UINib nibWithNibName:MY_CELL_IDENTIFIER bundle:[NSBundle mainBundle]]
forCellReuseIdentifier:MY_CELL_IDENTIFIER];
// -tableView: cellForRowAtIndexPath;
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:MY_CELL_IDENTIFIER];
// Creating a var with cell tag
UIImageView *imageView = (UIImageView *)[cell viewWithTag:IMAGEVIEW_TAG];
@inailuy
inailuy / keyboard resign
Last active December 12, 2015 12:39
resign keyboard from any view
[self.view.window endEditing:YES];
@inailuy
inailuy / Calling Number
Created February 15, 2013 22:00
Make a call from your iOS app
NSString *phoneNumber = [NSString stringWithFormat:@"tel:%@",phoneNumber];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
@inailuy
inailuy / Open Maps iOS
Created February 15, 2013 22:51
Open maps application in iOS with a location within a app.
NSString *mapsURL = @"http://maps.google.com/maps?q=";
if ([[[[UIDevice currentDevice] systemVersion] substringToIndex:1] intValue] >= 6) // if iOS 6 or greater use apple maps
{
mapsURL = @"http://maps.apple.com/maps?q=";
}
NSString *mapaddress = [mapsURL stringByAppendingString:address];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[mapaddress stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]];
@inailuy
inailuy / Shadows
Last active December 13, 2015 23:09
making a shadow for a view in iOS
//Adds a shadow to sampleView
CALayer *layer = self.sampleView.layer;
layer.shadowOffset = CGSizeMake(1, 1);
layer.shadowColor = [[UIColor blackColor] CGColor];
layer.shadowRadius = 4.0f;
layer.shadowOpacity = 0.80f;
layer.shadowPath = [[UIBezierPath bezierPathWithRect:layer.bounds] CGPath];
@inailuy
inailuy / Global App Delegate
Created February 21, 2013 19:57
Creating a global instance of app delegate for a iOS project
+ (AppDelegate *)instance
{
return (AppDelegate *)[UIApplication sharedApplication].delegate;
}
@inailuy
inailuy / int to NSString with format
Created February 22, 2013 16:56
For currencies or large numers that have commas after every 3 digits eg: 1,000,000 Converting int to string with commas money formatter
NSString *numberWithCommas = [NSNumberFormatter localizedStringFromNumber:@(intNumber)
numberStyle:NSNumberFormatterDecimalStyle];
@inailuy
inailuy / Adding NavigationBar Button
Last active December 14, 2015 02:48
Adding Navigation button to the right side
UIImage *buttonImage = [UIImage imageNamed:@"image"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 50, 44);
[button setImage:buttonImage forState:UIControlStateNormal];
[button addTarget:self
action:@selector(nil)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.rightBarButtonItem = barButtonItem;
#define WINDOW_WIDTH [[UIScreen mainScreen] bounds].size.width
#define WINDOW_HEIGHT [[UIScreen mainScreen] bounds].size.height
[navigationBar setBackgroundImage:[UIImage imageNamed:@"image"] forBarMetrics:UIBarMetricsDefault];