Skip to content

Instantly share code, notes, and snippets.

@sgoodwin
Created April 9, 2012 23:35
Show Gist options
  • Save sgoodwin/2347364 to your computer and use it in GitHub Desktop.
Save sgoodwin/2347364 to your computer and use it in GitHub Desktop.
Example file!
//
// GOViewController.h
// Example
//
// Created by Samuel Goodwin on 4/10/12.
// Copyright (c) Your Momma. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface GOViewController : UIViewController<UITextFieldDelegate>
@property(nonatomic, retain) UITextField *textField;
@end
//
// GOViewController.m
// Example
//
// Created by Samuel Goodwin on 4/10/12.
// Copyright (c) 2012 SNAP Interactive. All rights reserved.
//
#import "GOViewController.h"
@interface GOViewController ()
- (void)backgroundTapped:(UITapGestureRecognizer*)recoginizer;
@end
@implementation GOViewController
@synthesize textField = _textField;
- (void)viewDidLoad
{
[super viewDidLoad];
// Shane on you if you have magic numbers like this in your code.
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0.0f, 50.0f, 320.0f, 31.0f)];
[textField setBorderStyle:UITextBorderStyleRoundedRect];
[textField setBackgroundColor:[UIColor whiteColor]];
[textField setDelegate:self];
[self.view addSubview:textField];
self.textField = textField;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backgroundTapped:)];
[self.view addGestureRecognizer:tapGesture];
}
- (void)backgroundTapped:(UITapGestureRecognizer*)recoginizer{
[self.textField resignFirstResponder];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
[textField resignFirstResponder];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment