Skip to content

Instantly share code, notes, and snippets.

View danielphillips's full-sized avatar

Daniel Phillips danielphillips

  • Trainline
  • London, UK
View GitHub Profile
@interface SomeViewController : UIViewController
@end
@implementation SomeViewController
- (IBAction)show:(id)sender
{
UIImagePickerController *pickerController = [UIImagePickerController new];
[pickerController setDelegate:(id)self];
@danielphillips
danielphillips / gist:5490060
Created April 30, 2013 16:53
Show off all of an NSURL
NSDictionary *urlStuff = @{
@"absoluteString" : URL.absoluteString ? URL.absoluteString : @"nil",
@"relativeString" : URL.relativeString ? URL.relativeString : @"nil",
@"scheme" : URL.scheme ? URL.scheme : @"nil",
@"resourceSpecifier" : URL.resourceSpecifier ? URL.resourceSpecifier : @"nil",
@"host" : URL.host ? URL.host : @"nil",
@"port" : URL.port ? URL.port : @"nil",
@"user" : URL.user ? URL.user : @"nil",
@"password" : URL.password ? URL.password : @"nil",
@"path" : URL.path ? URL.path : @"nil",
NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
NSArray *fontNames;
NSInteger indFamily, indFont;
for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
{
NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
fontNames = [[NSArray alloc] initWithArray:
[UIFont fontNamesForFamilyName:
[familyNames objectAtIndex:indFamily]]];
@danielphillips
danielphillips / NSString+Crypto.h
Last active December 17, 2016 03:42
NSString Crypto category
#import <Foundation/Foundation.h>
#import <CommonCrypto/CommonHMAC.h>
@interface NSString (Crypto)
- (NSString *)md5;
+ (NSString *)encodeBase64WithString:(NSString *)strData;
+ (NSString *)encodeBase64WithData:(NSData *)objData;
+ (NSData *)decodeBase64WithString:(NSString *)strBase64;
- (NSString*)sha1;
@danielphillips
danielphillips / DPAnnotationView.h
Last active February 25, 2016 08:48
MKAnnotationView subclass to implement lift and drop animations for your custom map pin. Use this in exactly the same was as MKPinAnnotationView or use the implementation in conjunction with your existing MKAnnotationView subclass.
#import <MapKit/MapKit.h>
@interface DPAnnotationView : MKAnnotationView
@property (nonatomic, assign) MKMapView *mapView;
@end
- (IBAction)showWalkingDirections:(id)sender {
if ([self.parkingDetails.mapItem respondsToSelector:@selector(openInMapsWithLaunchOptions:)]) {
NSDictionary *launchOptions = @{
MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeWalking,
MKLaunchOptionsMapTypeKey : [NSNumber numberWithInt:MKMapTypeStandard]
};
[self.parkingDetails.mapItem openInMapsWithLaunchOptions:launchOptions];
} else {
NSString *mapURL = @"http://maps.google.com/maps?";
@danielphillips
danielphillips / DJPAppDelegate.h
Created February 8, 2012 22:11
Create a solid colour (no Apple gloss) UINavigationBar
@interface DJPAppDelegate : UIResponder <UIApplicationDelegate, UIAppearanceContainer>
@end
@danielphillips
danielphillips / UILabel+GetLines.h
Created June 9, 2011 16:45
Get number of lines required for a UILabel
@interface UILabel (GetLines)
- (NSArray*) lines;
@end
@danielphillips
danielphillips / UILabel+dynamicSizeMe.h
Created June 2, 2011 22:54
Adjust UILabel to change it's frame according to it's content
@interface UILabel (dynamicSizeMe)
-(float)resizeToFit;
-(float)expectedHeight;
@end
@danielphillips
danielphillips / DJPWebView.h
Created April 28, 2011 14:06
UILabel rich text solution using UIWebView
#import "DJPWebViewDelegate.h"
#import "DJPWebViewContent.h"
@interface DJPWebView : UIWebView {
DJPWebViewDelegate* delegateObject;
DJPWebViewContent* content;
}
@property(nonatomic, retain)DJPWebViewContent* content;