Skip to content

Instantly share code, notes, and snippets.

View danielphillips's full-sized avatar

Daniel Phillips danielphillips

  • Trainline
  • London, UK
View GitHub Profile
@danielphillips
danielphillips / LabelSizer.h
Created March 22, 2011 16:10
Allows you adjust a UILabel's height according to its content and retreive expected height for given input
@interface LabelSizer : NSObject {
}
+(float)getExpectedHeightForLabel:(UILabel*)label;
+(float)makeLabelCorrectSizeForCurrentWidth:(UILabel*)label;
+(float)getExpectedHeightForText:(NSString*)text withFontName:(NSString*)font atSize:(float)fontSize inContainerWidth:(float)width;
@end
@danielphillips
danielphillips / HTMLLineBreakConvertor.h
Created March 25, 2011 13:37
Convert raw HTML to basic text preserving line breaks for use in UILabel or UITextView
@interface HTMLLineBreakConvertor : NSObject <NSXMLParserDelegate> {
NSMutableString* resultString;
NSDictionary* tags;
}
- (NSString*)convertEntiesInString:(NSString*)s;
@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;
@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 / DJPAppDelegate.h
Created February 8, 2012 22:11
Create a solid colour (no Apple gloss) UINavigationBar
@interface DJPAppDelegate : UIResponder <UIApplicationDelegate, UIAppearanceContainer>
@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?";
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 / 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",
@interface SomeViewController : UIViewController
@end
@implementation SomeViewController
- (IBAction)show:(id)sender
{
UIImagePickerController *pickerController = [UIImagePickerController new];
[pickerController setDelegate:(id)self];
@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