Skip to content

Instantly share code, notes, and snippets.

View kylefox's full-sized avatar
🥊
programming

Kyle Fox kylefox

🥊
programming
View GitHub Profile
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[UIView
animateWithDuration:duration
animations:^{
self.gridView.contentOffset = CGPointMake(_currentPage * self.view.frame.size.height, 0);
}
completion:nil];
}
@kylefox
kylefox / GMGridViewCell.m
Created March 6, 2012 22:21
Some objective-c
- (void)setFullSize:(CGSize)fullSize
{
_fullSize = fullSize;
[self setNeedsLayout];
}
@kylefox
kylefox / _media_queries.sass
Created March 1, 2012 18:37 — forked from jcroft/layout.sass
How easy responsive design can be with Sass
=respond-to($device)
@if $device == handheld
@media only screen and (min-width : 320px)
@content
@if $device == handheld-landscape
@media only screen and (min-width : 321px)
@content
if(credentials) {
ProjectListViewController *projectList = [[ProjectListViewController alloc] init];
projectList.projects = [Portfolio portfolioWithCredentials:credentials].projects;
[self.navigationController pushViewController:projectList animated:NO];
} else {
// Instantiate LoginViewController and push it.
}
@kylefox
kylefox / gist:1774128
Created February 8, 2012 21:44
Fade in/out a view.
-(void) animateGridView:(BOOL)animateIn {
CAMediaTimingFunction *timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];
scaleAnim.timingFunction = opacityAnim.timingFunction = timingFunction;
CATransform3D endTransform;
CATransform3D fullScale = CATransform3DMakeScale(1, 1, 1);
-(void) setCaptionVisible:(BOOL)showCaption {
_captionVisible = showCaption;
_captionLabel.hidden = !_captionVisible;
_captionLabelContainer.hidden = !_captionVisible;
}
- (GMGridViewCell *)GMGridView:(GMGridView *)gridView cellForItemAtIndex:(NSInteger)index {
CGSize size = [self sizeForItemsInGMGridView:gridView];
// TODO: should be using dequeReusableCell, but that doesn't appear to be working here...
GMGridViewCell *cell = [[GMGridViewCell alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
Piece *piece = [self.project.pieces objectAtIndex:index];
PieceView *pieceView = [[PieceView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height) piece:piece];
pieceView.captionVisible = self.showCaption;
@kylefox
kylefox / PieceView.m
Created January 31, 2012 00:24
Create a vertically-resized, top-aligned, UILabel with padding.
// Create the _captionLabel:
_captionLabel = [[UILabel alloc] init];
_captionLabel.textColor = [UIColor colorWithRed:204 green:204 blue:204 alpha:1];
_captionLabel.backgroundColor = [UIColor clearColor];
_captionLabel.text = self.caption;
_captionLabel.numberOfLines = 0;
_captionLabel.lineBreakMode = UILineBreakModeWordWrap;
_captionLabel.font = [UIFont fontWithName:@"Helvetica" size:15];
// Calculate the frame for the caption according to a fixed width and variable size:
@kylefox
kylefox / color.m
Created January 27, 2012 17:45
Generate a random color (UIColor) in Objective-C
/*
Distributed under The MIT License:
http://opensource.org/licenses/mit-license.php
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
@implementation RALabel
- (void) drawRect:(CGRect)rect
{
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSelectFont (context, [self.font.fontName cStringUsingEncoding:NSASCIIStringEncoding], self.font.pointSize, kCGEncodingMacRoman);
CGContextSetCharacterSpacing(context, 1);