Skip to content

Instantly share code, notes, and snippets.

View zmcartor's full-sized avatar

Zach zmcartor

View GitHub Profile
UIVisualEffectView *vibrantView = [[UIVisualEffectView alloc] initWithEffect:[UIVibrancyEffect effectForBlurEffect:blur]]; vibrantView.frame = blurView.bounds; 
UILabel *label = [[UILabel alloc] init]; 
[label setFont:[UIFont fontWithName:@"HelveticaNeue" size:33]]; label.frame = CGRectMake(8, 30, 400, 500); 
label.numberOfLines = 0; 
label.text = @"THIS IS VIBRANT TEXT!"; 

// add vibrantView to first blurView
[vibrantView.contentView addSubview:label];
[blurView.contentView addSubview:vibrantView];
UIBlurEffect *blur =[UIBlurEffecteffectWithStyle:UIBlurEffectStyleDark]; 
UIVisualEffectView *blurView = [[UIVisualEffectView alloc] initWithEffect:blur]; 
blurView.frame = self.hudView.bounds; 
[self.view addSubview:blurView];
@zmcartor
zmcartor / gist:b9d25d1c6319428d400c
Created September 16, 2014 14:56
ScrollView direction
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
CGPoint translation = [scrollView.panGestureRecognizer translationInView:scrollView.superview];
if(translation.y > 0)
{
NSLog(@"dragging downwards!");
} else
{
NSLog(@"dragging up!");
}
@zmcartor
zmcartor / gist:9f203d4f15f6310af449
Created September 9, 2014 17:26
Center ScrollView Contents
// Can also be placed within scrollviews layoutSubviews
- (void)centerScrollViewContents {
CGSize boundsSize = self.scrollView.bounds.size;
CGRect contentsFrame = self.imageView.frame;
if (contentsFrame.size.width < boundsSize.width) {
contentsFrame.origin.x = (boundsSize.width - contentsFrame.size.width) / 2.0f;
} else {
contentsFrame.origin.x = 0.0f;
@zmcartor
zmcartor / gist:857c43c821cfcf75e555
Created September 9, 2014 17:25
Zoom Scrollview
- (void)scrollViewDoubleTapped:(UITapGestureRecognizer*)recognizer {
// 1
CGPoint pointInView = [recognizer locationInView:self.imageView];
// 2
CGFloat newZoomScale = self.scrollView.zoomScale * 1.5f;
newZoomScale = MIN(newZoomScale, self.scrollView.maximumZoomScale);
// 3
CGSize scrollViewSize = self.scrollView.bounds.size;
@zmcartor
zmcartor / gist:2f8f06cf614c3c6b3267
Created September 2, 2014 15:40
TextField empty and filter out 'return' key
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSString *filteredString = [string stringByReplacingOccurrencesOfString:@"\n" withString:@""];
NSInteger textLength = [textField.text length] - range.length + [filteredString length];
if (textLength > 0) {
self.redeemButton.enabled = YES;
}
else {
@zmcartor
zmcartor / gist:73bcc143faa99af202b3
Created August 15, 2014 00:30
Cocoa Responder Chain and UITableViews
// Whenever a button, tap , or something 'happens' within a cell subclass, send a message up thee olde Responder Chain
// -- within tablecell_subclass.m
- (IBAction)connectButtonClicked:(id)sender {
SEL selConnectButton = sel_registerName("connectButtonResponder:");
[[UIApplication sharedApplication] sendAction:selConnectButton to:nil from:self forEvent:nil];
}
// within the UITableViewController , responde to the selector "connectButtonResponder"
@zmcartor
zmcartor / gist:281f3b62b6afa0aa7c9b
Last active August 29, 2015 14:00
Mergesort in Javascript
// classical merge algo
Array.prototype.mergesort = function() {
console.log(this)
if(this.length == 1) {
return this;
}
var merge = function(left, right){
var sorted = [];
var l = r = 0;
while(l < left.length && r < right.length){
@zmcartor
zmcartor / helloWorldMotion.rb
Created May 20, 2013 22:44
Quickest iOS app ever! :)
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
alert = UIAlertView.alloc.initWithTitle("Oh yeah!", message:"OHHAI!", delegate:nil, cancelButtonTitle:"OK", otherButtonTitles:nil)
alert.show
true
end
end
@zmcartor
zmcartor / gist:5481594
Created April 29, 2013 13:31
FlatColor iOS UIColor Example
// Example for Turquoise
// rgb(26, 188, 156)
[UIColor colorWithRed:26/255.0f green:188/255.0f blue:156/255.0f alpha:1.0];