Skip to content

Instantly share code, notes, and snippets.

View mteece's full-sized avatar
🏠
Working from home

Matthew Teece mteece

🏠
Working from home
View GitHub Profile
@mteece
mteece / activityindicator.m
Created December 21, 2012 16:33
Customize activity indicator centered in a view (with frame) and transparent background.
_activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] ;
_activityIndicatorView.center = [[self tableView] center];
_activityIndicatorView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.75];
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
// Time for some geometry. The 150 is the frame width and 150 is the height.
// These are static in code for now. Potential to make another view to reuse.
@mteece
mteece / subviewtag.m
Created December 20, 2012 15:17
Removing subviews from a view by tag.
// Each UIView object has a tag property which is simply an integer value
// that can be used to identify that view. You could set the tag value of
// each added view to 7 like this. The use the for loop to clean up the
// subview if needed.
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self.view];
CGRect myImageRect = CGRectMake((touchPoint.x -50), (touchPoint.y -50), 80.0f, 90.0f);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
@mteece
mteece / uitoolbarappearance.m
Created December 14, 2012 14:42
Customize UIToolbar via appearance API.
[[UIToolbar appearance] setTintColor:[UIColor colorWithRed:0.157 green:0.169 blue:0.235 alpha:1.0]];
@mteece
mteece / appearance.m
Created December 12, 2012 19:31
UINavigationBar appearance API.
// Customize the title text for *all* UINavigationBars
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
UITextAttributeTextColor,
[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"Arial-Bold" size:0.0],
@mteece
mteece / defaultuinavigationbarimage.m
Created December 11, 2012 20:46
Set the default UINavigationBar background image (and baseColor) app wide. Needs the @2x as well.
// For .h file - (void) customizeAppearance; and @property (nonatomic, retain) UIColor *baseColor;
// For .m file.
- (void) customizeAppearance
{
_baseColor = [[UIColor alloc] initWithCIColor:[CIColor colorWithRed:0.157
green:0.169
blue:0.235
alpha:1.0]];
@mteece
mteece / cachelength.js
Created December 10, 2012 16:03
Cache the array length to speed up for loop. Preassign the array length instead of testing it again in every step.
/* //Below code is causing the slowdown
for (var i = 0; i < records.length; i++) {
var record = new recordTemplate(records[i]);
this.store.add(record);
}
},
*/
// Better code
var records2 = [];
@mteece
mteece / uiimagefromurl.m
Created December 10, 2012 00:33
UIImage from image URL.
// UIImage from image URL.
NSURL *url = [NSURL URLWithString:@"http://example.com/image.jpg"];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
@mteece
mteece / unusedvariable.m
Created December 9, 2012 22:55
Using *__unused* to tell LLVM to ignore unused variable in XCode 4.3.2, example with Underscore.m
// Uses http://underscorem.org/
// #import "USArrayWrapper.h"
// Wraps an array in Underscore.m's USArrayWrapper. This is crucial in order to use the
// other methods. The *__unused* tells LLVM to ignore unused variable in XCode 4.3.2.
USArrayWrapper *wrapper __unused = _array(serviceRequests);
_array(serviceRequests).each(^(id obj) {
RequestModel *req = (RequestModel *)obj;
NSLog(@"Object: %@", req
});
@mteece
mteece / nsarrayradius.m
Created December 6, 2012 19:03
Search array of locations within a radius
// NSArray *locations as an array of CLLocation* that you wish to filter
// with a given radius constant.
CLLocationDistance radius = kSomeRadius;
// Target you want to test against to see if it is within the radius bounds.
CLLocation* target = [[CLLocation alloc] initWithLatitude:someLat longitude:someLon];
NSArray *locationsWithinRadius = [locations objectsAtIndexes:
[locations indexesOfObjectsPassingTest:
^BOOL(id obj, NSUInteger idx, BOOL *stop) {
@mteece
mteece / RecentRequestsViewController.m
Created November 29, 2012 00:57
UIViewController UIBarButtonItem title and add to left/right bar buttons array.
#import "RecentRequestsViewController.h"
#import "AppDelegate.h"
@interface RecentRequestsViewController ()
@end
@implementation RecentRequestsViewController
#pragma mark -