Skip to content

Instantly share code, notes, and snippets.

@darkseed
darkseed / gist:1141193
Created August 12, 2011 00:43
Set CFBundleVersion to current Git revision
/usr/libexec/PlistBuddy -c "Set CFBundleVersion `git rev-parse --short HEAD`" "$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
@darkseed
darkseed / gist:1144974
Created August 14, 2011 15:21
CABasicAnimation text animation
//Create a CABasicAnimation object. Must be added to the element after it is displayed
CATransition *animation = [CATransition animation];
animation.duration = 1.0;
animation.type = kCATransitionFade;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[myLabel.layer addAnimation:animation forKey:@"changeTextTransition"];
// Change the text and the animation will ocur
myLabel.text = @"Changed text";
@darkseed
darkseed / gist:1144976
Created August 14, 2011 15:22
CABasicAnimation movement
//Create a CABasicAnimation object
CABasicAnimation *move = [CABasicAnimation animationWithKeyPath:@"transform.translation.y" ];
[move setFromValue:[NSNumber numberWithFloat:0.0f]];
[move setToValue:[NSNumber numberWithFloat:100.0f]];
[move setDuration:0.3f];
//Add animation to a specific element's layer. Must be called after the element is displayed.
[[element layer] addAnimation:move forKey:@"transform.translation.y"];
@darkseed
darkseed / gist:1144982
Created August 14, 2011 15:26
Custom UISlider
UISlider *slider = [[UISlider alloc] init];
UIImage *sliderLeftTrackImage = [[UIImage imageNamed: @"slider_body_min.png"] stretchableImageWithLeftCapWidth: 9 topCapHeight: 0];
UIImage *sliderRightTrackImage = [[UIImage imageNamed: @"slider_body_max.png"] stretchableImageWithLeftCapWidth: 9 topCapHeight: 0];
UIImage *sliderThumb = [[UIImage imageNamed: @"slider_thumb.png"] stretchableImageWithLeftCapWidth: 9 topCapHeight: 0];
[slider setMinimumTrackImage: sliderLeftTrackImage forState: UIControlStateNormal];
[slider setMaximumTrackImage: sliderRightTrackImage forState: UIControlStateNormal];
[slider setThumbImage:sliderThumb forState:UIControlStateNormal];
// Now place you slider in a view and do anything else you want
@darkseed
darkseed / gist:1144990
Created August 14, 2011 15:33
Custom UINavigation background
@interface UINavigationBar (MyCustomNavBar)
@end
@implementation UINavigationBar (MyCustomNavBar)
- (void) drawRect:(CGRect)rect {
//matching the button color with the bar color
[self setTintColor:[UIColor colorWithRed:0.85f green: 0 blue:0 alpha:1]];
UIImage *barImage = [UIImage imageNamed:@"image.png"];
[barImage drawInRect:rect];
}
@end
@darkseed
darkseed / gist:1145005
Created August 14, 2011 15:47
Multiple buttons UINavigation
// Create the toobar
UIToolbar* toolbar = [[UIToolbar alloc]
initWithFrame:CGRectMake(0, 0, 100, 45)];
[toolbar setBarStyle: UIBarStyleDefault];
// Create and array for the buttons
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];
// Create a "+" button
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
@darkseed
darkseed / AppDelegate.m
Created August 19, 2011 18:10
UITabBarController+CCAdditions.h
#import "UITabBarController+CCAdditions.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[tabBarController setBackgroundImage:[UIImage imageNamed:@"CustomTabBarBackground.png"]];
[tabBarController.view setNeedsDisplay];
return YES;
}
@darkseed
darkseed / checkforgyro.m
Created August 20, 2011 17:21
Check for Gyroscope
- (BOOL) isGyroscopeAvailable
{
#ifdef __IPHONE_4_0
CMMotionManager *motionManager = [[CMMotionManager alloc] init];
BOOL gyroAvailable = motionManager.gyroAvailable;
[motionManager release];
return gyroAvailable;
#else
return NO;
#endif
@darkseed
darkseed / retinacheck.m
Created August 20, 2011 17:22
Check for retina display
+ (BOOL) isRetinaDisplay
{
int scale = 1.0;
UIScreen *screen = [UIScreen mainScreen];
if([screen respondsToSelector:@selector(scale)])
scale = screen.scale;
if(scale == 2.0f) return YES;
else return NO;
}
@darkseed
darkseed / gist:1159375
Created August 20, 2011 17:24
Check for photos and camera
// Method returns no, when the user doesn't have any photos
[UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary];
// Check for camera
- (BOOL) isVideoCameraAvailable
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
NSArray *sourceTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType];
[picker release];