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+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 / 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?";
@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
@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;
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]]];