Skip to content

Instantly share code, notes, and snippets.

View dlinsin's full-sized avatar

David Linsin dlinsin

View GitHub Profile
// this is implemented, but not declared. we add the category to fix the warning
// (since super cannot be casted any longer in clang)
@interface UINavigationController(AMInternal)
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item;
@end
@implementation AMNavigationController
///////////////////////////////////////////////////////////////////////////////////////////////////
@darkseed
darkseed / multi line label.m
Created August 20, 2011 20:05 — forked from chrishulbert/multi line label.m
How to make a multiline label with dynamic text on the iphone and get the correct height
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 9999)];
myLabel.lineBreakMode = UILineBreakModeWordWrap;
myLabel.numberOfLines = 0;
myLabel.text = @"Some \n dynamic \n multiline \n text";
[myLabel sizeToFit]; // This shrinks the 9999 down to the size of the text
NSLog(@"Actual height is: %f", myLabel.frame.size.height); // Use this for spacing any further elements
[self.view addSubview:title]; // Or add it to a scroll view, or whatever...
[myLabel release];
@mikeyk
mikeyk / (deprecated)UINotificationKeyboardHeight.m
Created September 8, 2011 23:31
Get keyboard height from an NSNotification
@implementation NSNotification (KeyboardHeight)
- (CGFloat)keyboardHeight {
CGRect bounds;
NSValue *boundsValue = [self.userInfo objectForKey:UIKeyboardBoundsUserInfoKey];
if (boundsValue) {
[boundsValue getValue:&bounds];
return bounds.size.height;
} else {
return 0;
@stevestreza
stevestreza / NSURL+Pieces.h
Created September 26, 2011 19:52
A method for debugging NSURLs to find where the different pieces of your URL are
#import <Foundation/Foundation.h>
@interface NSURL (Pieces)
-(NSDictionary *)piecesDictionary;
@end
@wess
wess / UIButton+Addition.h
Created January 21, 2012 16:00
added setBackground for event to UIButton
#import <UIKit/UIKit.h>
@interface UIButton(WCButton)
@property (nonatomic, retain) NSMutableDictionary *backgrounds;
- (void) setBackgroundColor:(UIColor *)bgColor forState:(UIControlState)state;
@end
@steipete
steipete / gist:2255253
Created March 30, 2012 21:25
ISO 8601 parsing
+ (NSDate *)dateFromISO8601String:(NSString *)iso8601 {
if (!iso8601) {
return nil;
}
const char *str = [iso8601 cStringUsingEncoding:NSUTF8StringEncoding];
char newStr[24];
struct tm tm;
size_t len = strlen(str);
@conradev
conradev / simulatorconsole
Last active December 16, 2015 00:45
simulatorconsole
#!/bin/bash
tail -f $(ls -t "$HOME/Library/Logs/CoreSimulator/"*/system.log | head -1)
@chbeer
chbeer / other c flags
Last active December 21, 2015 17:18
My current "other c flags" setting for get a good amount of warnings and turn the most important/dangerous warnings into errors.
-Wall
-Wno-deprecated-declarations
-Werror=incompatible-pointer-types
-Werror=arc-retain-cycles
-Werror=implicit-function-declaration
-Werror=return-type
-Werror=format
-Werror=mismatched-parameter-types
-Werror=tautological-constant-out-of-range-compare
@steipete
steipete / gist:1175357
Created August 27, 2011 12:54
Easy [fade] animation for UIImageView.image
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
selected_ = selected;
if (animated) {
CATransition *transition = [CATransition animation];
transition.duration = 0.25f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self.selectionImageView.layer addAnimation:transition forKey:nil];
}
@indragiek
indragiek / DynamicTypeLabel.swift
Last active August 25, 2017 15:08
UILabel subclass that automatically adjusts the font when the global dynamic type setting changes.
//
// DynamicTypeLabel.swift
//
// Created by Indragie on 10/16/14.
// Copyright (c) 2014 Indragie Karunaratne. All rights reserved.
//
import UIKit
class DynamicTypeLabel : UILabel {