Skip to content

Instantly share code, notes, and snippets.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (self.tabBarController.selectedViewController == self.navigationController)
return NO;
else
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@implementation UINavigationBar (WoodenBG)
- (void) drawRect:(CGRect)rect
{
[super drawRect:rect];
[[UIImage imageNamed:@"navigationBar.png"] drawInRect:rect];
}
@end
/*
Add a UISearchBar IBOutlet to your table view controller
Add a search bar to your xib file with Interface Builder by dragging it into the table view
Connect the search bar to it’s outlet
Change the table view’s bounds property to hide the search bar (see code below)
 
*/
 
@darkseed
darkseed / TextViewPinchToZoom
Created May 11, 2011 11:33 — forked from aral/TextViewPinchToZoom
How to use add pinch-to-zoom to a TextView
// Create a pinch gesture recognizer instance.
self.pinchGestureRecognizer = [[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGesture:)] autorelease];
// And add it to your text view.
[self.myTextView addGestureRecognizer:self.pinchGestureRecognizer];
// ...
- (void)pinchGesture:(UIPinchGestureRecognizer *)gestureRecognizer
{
@darkseed
darkseed / Curved_shadow.m
Created May 11, 2011 22:13
Curved shadow below an image
#import <QuartzCore/QuartzCore.h>
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *image = [UIImage imageNamed:@"photo.png"];
UIView *photoView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, image.size.width, image.size.height)];
photoView.center = CGPointMake(self.view.center.x, self.view.center.y - 10);
@darkseed
darkseed / gist:967514
Created May 11, 2011 22:16
Output properties of an object
- ( NSString *) Description
{
NSMutableString * String = [ NSMutableString stringWithString : @ "" ];
unsigned int propertyCount;
objc_property_t * Properties = class_copyPropertyList ([ Self class ], & propertyCount);
for ( unsigned int I = 0 ; I "propertyCount; I + +)
{
NSString * Selector = [ NSString stringWithCString : property_getName (Properties [I]) encoding : NSUTF8StringEncoding ];
@darkseed
darkseed / gist:967518
Created May 11, 2011 22:21
Singletons in Objective C
// A normal singleton
static AppInfo * sharedAppInfo = nil;
+ (AppInfo *) sharedAppInfo
{
if ( sharedAppInfo == nil )
{
[[self alloc] init];
}
return sharedAppInfo;
@darkseed
darkseed / gist:967546
Created May 11, 2011 22:39
Objective-C Timer macros
#define START_TIMER NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
#define END_TIMER(msg) NSTimeInterval stop = [NSDate timeIntervalSinceReferenceDate]; LPLog([NSString stringWithFormat:@"%@ Time = %f", msg, stop-start]);
// Example usage
- (void)loadStockCodeMaster
{
START_TIMER;
NSURL *url = [NSURL URLWithString:STOCK_CODE_MASTER_URL];
NSString *stringFile = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
END_TIMER(@"loadStockCodeMaster");
@darkseed
darkseed / DataManager.h
Created May 21, 2011 19:54 — forked from NachoMan/DataManager.h
Core Data singleton manager class capable of being run from a static library
// DataManager.h
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
extern NSString * const DataManagerDidSaveNotification;
extern NSString * const DataManagerDidSaveFailedNotification;
@interface DataManager : NSObject {
}
@darkseed
darkseed / ec2-ssh.rb
Created May 23, 2011 19:30 — forked from qwzybug/ec2-ssh.rb
SSH into an EC2 instance by name.
#!/usr/bin/env ruby
instance_name = ARGV[0]
abort "Please specify an instance name" unless instance_name and instance_name.length > 0
instance_info, selected_instance = {}, nil
info_keymap = {2 => :ami_id, 3 => :address, 5 => :status, 6 => :keypair_name}
instances = `ec2-describe-instances`.split("\n").map{|l| l.split("\t")}
instances.each do |line|