Skip to content

Instantly share code, notes, and snippets.

@mluton
mluton / gist:5352050
Created April 10, 2013 05:29
Detect which subview was tapped
- (void)handleTapFrom:(UITapGestureRecognizer *)recognizer
{
CGPoint point = [recognizer locationInView:self.view];
UIView *tappedView = [self.view hitTest:point withEvent:nil];
if ([tappedView isKindOfClass:[SingleDesignerView class]]) {
int row = ((SingleDesignerView*)tappedView).row;
NSDictionary *designer = self.designers[row];
NSLog(@"person: %@ %@", designer[@"name"], designer[@"slug"]);
@mluton
mluton / gist:5323538
Created April 5, 2013 23:49
Put an NSAttributedString into a CATextLayer. This works in iOS 5.
CATextLayer *textLayer = [CATextLayer layer];
textLayer.backgroundColor = [UIColor whiteColor].CGColor;
textLayer.frame = CGRectMake(20, 20, 200, 100);
textLayer.contentsScale = [[UIScreen mainScreen] scale];
CTFontRef fontFace = CTFontCreateWithName((__bridge CFStringRef)(@"HelfaSemiBold"), 24.0, NULL);
NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
[attributes setObject:(__bridge id)fontFace forKey:(NSString*)kCTFontAttributeName];
[attributes setObject:[UIColor blackColor] forKey:(NSString*)kCTForegroundColorAttributeName];
NSAttributedString *attrStr = [[NSAttributedString alloc] initWithString:@"Lorem Ipsum" attributes:attributes];
@mluton
mluton / gist:4534602
Created January 14, 2013 23:40
UIColor with RGB values
[UIColor colorWithRed:190/255.f green:190/255.f blue:193/255.f alpha:1.0]
@mluton
mluton / gist:4495817
Created January 9, 2013 18:57
iOS: Generate email compose screen pre-populated with system information
if ([MFMailComposeViewController canSendMail]) {
NSString *iosVersion = [[UIDevice currentDevice] systemVersion];
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *appVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
mailViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[mailViewController setToRecipients:@[@"[email protected]"]];
[mailViewController setMessageBody:[NSString stringWithFormat:@"<br/><br/><hr size=1><strong>UTC Chart Information</strong><br/>App Version: %@<br/>iOS Version: %@<hr size=1>", appVersion, iosVersion] isHTML:YES];
@mluton
mluton / gist:4495466
Created January 9, 2013 18:18
Set the network activity indicator in iOS.
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[[UIApplication sharedApplication] setnetworkActivityIndicatorVisible:NO];
@mluton
mluton / gist:4395363
Created December 28, 2012 07:23
Simple Splash Screen for iOS
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
UIImageView*imageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Default.png"]];
[[self.viewController view] addSubview:imageView];
[[self.viewController view] bringSubviewToFront:imageView];
@mluton
mluton / gist:4283232
Created December 14, 2012 06:48
Create string from unicode.
// Guaranteed to get the characters in the 'illegal' ranges the compiler will complain about.
NSMutableAttributedString *attrStr = [NSMutableAttributedString attributedStringWithString:[NSString stringWithFormat:@"%C", (unsigned short)0xe007]];
// Same thing but use a string as the original source of the unicode instead of a literal.
unsigned int intValue;
NSScanner* scanner = [NSScanner scannerWithString:@"e007"];
[scanner scanHexInt:&intValue];
NSMutableAttributedString *attrStr = [NSMutableAttributedString attributedStringWithString:[NSString stringWithFormat:@"%C", (unsigned short)intValue]];
@mluton
mluton / gist:4151489
Created November 27, 2012 00:04
Git Ignore for iOS Projects
.DS_Store
*.swp
*~
*~.nib
*.orig
build/
*.pbxuser
*.perspective
*.perspectivev3
@mluton
mluton / gist:4121189
Created November 20, 2012 21:16
Read a plist into an Array
NSMutableArray *typefaceLibrary = [[NSMutableArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"typeface-library" ofType:@"plist"]];
@mluton
mluton / gist:4114695
Created November 19, 2012 23:06
Remove Shadow From Web View
// The easy way. iOS 5.x+
self.webView.scrollView.bounces = NO;
// The hard way.
// Remove the shadow from behind the webview which appears if the web view
// is scrolled past its the top or bottom.
// http://stackoverflow.com/a/4167060/99683
for (UIView* subView in [webView subviews]) {
if ([subView isKindOfClass:[UIScrollView class]]) {
for (UIView* shadowView in [subView subviews]) {