Skip to content
Browse files

Reorganisation, cleanup, ARCified.

- Reorganisation
- Fixed compiler warnings and imports
- Removed some parts, added some others
- Converted to ARC
  • Loading branch information...
1 parent 99bc2d4 commit 8ef8604a97c565449dcd01f9da4f50c439e59c47 Marcel Ruegenberg committed Aug 24, 2012
Showing with 408 additions and 1,062 deletions.
  1. +3 −0 {CoreFoundationAdditions → CoreFoundation/Date+Time}/NSDate+Additions.h
  2. +9 −4 {CoreFoundationAdditions → CoreFoundation/Date+Time}/NSDate+Additions.m
  3. 0 {Util → CoreFoundation/Date+Time}/TimeHelpers.h
  4. +5 −4 {Util → CoreFoundation/Date+Time}/TimeHelpers.m
  5. +2 −2 {CoreFoundationAdditions → CoreFoundation/NSArray}/FPTuple.h
  6. +2 −8 {CoreFoundationAdditions → CoreFoundation/NSArray}/FPTuple.m
  7. 0 {CoreFoundationAdditions → CoreFoundation/NSArray}/NSArray+FPAdditions.h
  8. +2 −2 {CoreFoundationAdditions → CoreFoundation/NSArray}/NSArray+FPAdditions.m
  9. +43 −0 CoreFoundation/NSData/NSData+Base64.h
  10. +80 −69 {CoreFoundationAdditions → CoreFoundation/NSData}/NSData+Base64.m
  11. 0 {CoreFoundationAdditions → CoreFoundation/NSData}/NSData+CocoaDevUsersAdditions.h
  12. 0 {CoreFoundationAdditions → CoreFoundation/NSData}/NSData+CocoaDevUsersAdditions.m
  13. 0 {CoreFoundationAdditions → CoreFoundation/NSObject}/NSObject+KVCExtensions.h
  14. +2 −1 {CoreFoundationAdditions → CoreFoundation/NSObject}/NSObject+KVCExtensions.m
  15. 0 {CoreFoundationAdditions → CoreFoundation/NSObject}/NSObject+ObserveActions.h
  16. +0 −4 {CoreFoundationAdditions → CoreFoundation/NSObject}/NSObject+ObserveActions.m
  17. +16 −0 CoreFoundation/NSString/NSString+Hash.h
  18. +24 −0 CoreFoundation/NSString/NSString+Hash.m
  19. 0 {CoreFoundationAdditions → CoreFoundation/NSString}/NSString+StringAdditions.h
  20. 0 {CoreFoundationAdditions → CoreFoundation/NSString}/NSString+StringAdditions.m
  21. 0 {CoreFoundationAdditions → CoreFoundation/Other}/NSURL+ParameterParsing.h
  22. 0 {CoreFoundationAdditions → CoreFoundation/Other}/NSURL+ParameterParsing.m
  23. +0 −33 CoreFoundationAdditions/NSData+Base64.h
  24. +0 −15 CoreFoundationAdditions/NSString+PercentEscape.h
  25. +0 −23 CoreFoundationAdditions/NSString+PercentEscape.m
  26. +0 −14 CoreFoundationAdditions/TimeHelpers.h
  27. +0 −23 CoreFoundationAdditions/TimeHelpers.m
  28. +0 −303 CoreGraphicsUtils/PathUtils.c
  29. +0 −44 CoreGraphicsUtils/PathUtils.h
  30. +0 −25 DLFolding.h
  31. +5 −1 README.mdown
  32. +0 −68 SynthesizeSingleton.h
  33. +3 −3 {UIKitUtils → UIKit/Controls}/PopoverManager.h
  34. +6 −5 {UIKitUtils → UIKit/Controls}/PopoverManager.m
  35. +3 −1 UIKitUtils/UIPlaceHolderTextView.h → UIKit/Controls/UIPlaceholderTextView.h
  36. +1 −5 UIKitUtils/UIPlaceHolderTextView.m → UIKit/Controls/UIPlaceholderTextView.m
  37. +22 −0 UIKit/Controls/UITabBarController+HideableTabBar.h
  38. +1 −1 {UIKitAdditions → UIKit/Controls}/UITabBarController+HideableTabBar.m
  39. 0 {UIKitAdditions → UIKit/Drawing}/InnerShadowDrawing.h
  40. +1 −1 {UIKitAdditions → UIKit/Drawing}/InnerShadowDrawing.m
  41. +11 −0 {UIKitAdditions → UIKit/Drawing}/UIColor+HelperAdditions.h
  42. 0 {UIKitAdditions → UIKit/Drawing}/UIColor+HelperAdditions.m
  43. +2 −0 {UIKitAdditions → UIKit/Drawing}/UIImage+Additions.h
  44. +2 −1 {UIKitAdditions → UIKit/Drawing}/UIImage+Additions.m
  45. +2 −0 {UIKitAdditions → UIKit/Drawing}/UIKit+DrawingHelpers.h
  46. +14 −17 {UIKitAdditions → UIKit/Drawing}/UIKit+DrawingHelpers.m
  47. +4 −0 {UIKitAdditions → UIKit/Utility}/UIControl+DLBlockAdditions.h
  48. +10 −6 {UIKitAdditions → UIKit/Utility}/UIControl+DLBlockAdditions.m
  49. +16 −0 UIKit/Utility/UIDeviceHardware.h
  50. +49 −0 UIKit/Utility/UIDeviceHardware.m
  51. +15 −0 UIKit/ViewUtil/UIKitHelpers.h
  52. +52 −0 UIKit/ViewUtil/UIKitHelpers.m
  53. 0 {UIKitAdditions → UIKit/ViewUtil}/UIView+Additions.h
  54. 0 {UIKitAdditions → UIKit/ViewUtil}/UIView+Additions.m
  55. BIN UIKit/ViewUtil/delete_button.png
  56. BIN UIKit/ViewUtil/delete_button@2x.png
  57. BIN UIKit/ViewUtil/light_button.png
  58. BIN UIKit/ViewUtil/light_button@2x.png
  59. +0 −25 UIKitAdditions/UIImage+Resize.h
  60. +0 −188 UIKitAdditions/UIImage+Resize.m
  61. +0 −15 UIKitAdditions/UIImage+RoundedCorner.h
  62. +0 −46 UIKitAdditions/UIImage+RoundedCorner.m
  63. +0 −17 UIKitAdditions/UITabBarController+HideableTabBar.h
  64. +0 −19 UIKitAdditions/UIView+Sliding.h
  65. +0 −69 UIKitAdditions/UIView+Sliding.m
  66. 0 {Util → }/Util.h
  67. +1 −0 {Util → }/Util.m
View
3 CoreFoundationAdditions/NSDate+Additions.h → CoreFoundation/Date+Time/NSDate+Additions.h
@@ -99,6 +99,9 @@
- (NSInteger)daysSinceDateFast:(NSDate *)date;
- (BOOL)isWeekend;
+
+- (BOOL)isEarlier:(NSDate *)other;
+- (BOOL)isLater:(NSDate *)other;
@end
View
13 CoreFoundationAdditions/NSDate+Additions.m → CoreFoundation/Date+Time/NSDate+Additions.m
@@ -16,7 +16,7 @@
NSCalendar *curCalendar() {
static NSCalendar *calendar = nil;
- if(calendar == nil) calendar = [[NSCalendar autoupdatingCurrentCalendar] retain];
+ if(calendar == nil) calendar = [NSCalendar autoupdatingCurrentCalendar];
return calendar;
}
@@ -31,7 +31,6 @@ BOOL is24HourFormat() {
NSRange amRange = [dateString rangeOfString:[formatter AMSymbol]];
NSRange pmRange = [dateString rangeOfString:[formatter PMSymbol]];
is24Hour = (amRange.location == NSNotFound && pmRange.location == NSNotFound);
- [formatter release];
determined = YES;
}
return is24Hour;
@@ -112,13 +111,12 @@ - (NSDate *)dateByAddingDays:(NSInteger)days {
NSDateComponents *dC = [[NSDateComponents alloc] init];
dC.day = days;
NSDate *res = [curCalendar() dateByAddingComponents:dC toDate:self options:0];
- [dC release];
return res;
}
- (NSDate *)dateByAddingMinutes:(NSInteger)minutes {
NSInteger secsToAdd = 60 * minutes;
- return [[[NSDate alloc] initWithTimeInterval:secsToAdd sinceDate:self] autorelease];
+ return [[NSDate alloc] initWithTimeInterval:secsToAdd sinceDate:self];
}
- (NSDate *)prevDay {
@@ -227,6 +225,13 @@ - (BOOL)isWeekend {
return weekdayOfDate == weekdayRange.location || weekdayOfDate == weekdayRange.length;
}
+- (BOOL)isEarlier:(NSDate *)other {
+ return [self earlierDate:other] == self;
+}
+- (BOOL)isLater:(NSDate *)other {
+ return [self laterDate:other] == self;
+}
+
@end
View
0 Util/TimeHelpers.h → CoreFoundation/Date+Time/TimeHelpers.h
File renamed without changes.
View
9 Util/TimeHelpers.m → CoreFoundation/Date+Time/TimeHelpers.m
@@ -61,8 +61,9 @@
NSString *timeIntervalToString(NSInteger timeInterval) {
if(timeInterval == 0) return NSLocalizedStringWithDefaultValue(@"Time None", @"Generic", [NSBundle mainBundle], @"None", @"Text that describes a time interval of zero length");
- NSString *prefix = @"";
- NSString *suffix = timeInterval < 0 ? NSLocalizedStringWithDefaultValue(@"Time Before Suffix", @"Generic", [NSBundle mainBundle], @"before", @"Suffix that describes that something occured before something else, i.e the 'before' in '60 minutes before'") : NSLocalizedStringWithDefaultValue(@"Time After Suffix", @"Generic", [NSBundle mainBundle], @"after", @"Suffix that describes that something occured after something else, i.e the 'after' in 'Ring the bell 60 minutes after the event'");
- prefix = timeLengthToString(timeInterval);
- return [NSString stringWithFormat:@"%@ %@", prefix, suffix];
+ NSString *format = NSLocalizedStringWithDefaultValue(@"Time Interval Format", @"Generic", [NSBundle mainBundle], @"%1$@ %2$@", @"Format for time interval strings. If the normal order would be like '5 minutes after', leave it as '1 2', if in your language the 'after' would come after the rest, change the order, i.e '2 1'");
+ NSString *timeLen = @"";
+ NSString *indicator = timeInterval < 0 ? NSLocalizedStringWithDefaultValue(@"Time Before Suffix", @"Generic", [NSBundle mainBundle], @"before", @"Suffix that describes that something occured before something else, i.e the 'before' in '60 minutes before'") : NSLocalizedStringWithDefaultValue(@"Time After Suffix", @"Generic", [NSBundle mainBundle], @"after", @"Suffix that describes that something occured after something else, i.e the 'after' in 'Ring the bell 60 minutes after the event'");
+ timeLen = timeLengthToString(timeInterval);
+ return [NSString stringWithFormat:format, timeLen, indicator];
}
View
4 CoreFoundationAdditions/FPTuple.h → CoreFoundation/NSArray/FPTuple.h
@@ -17,8 +17,8 @@
id snd;
}
-@property (nonatomic, retain) id fst;
-@property (nonatomic, retain) id snd;
+@property (nonatomic, strong) id fst;
+@property (nonatomic, strong) id snd;
- (id)initWithFirst:(id)fst second:(id)snd;
+ (id)tupleWithFirst:(id)fst second:(id)snd;
View
10 CoreFoundationAdditions/FPTuple.m → CoreFoundation/NSArray/FPTuple.m
@@ -21,15 +21,9 @@ - (id)initWithFirst:(id)first second:(id)second {
}
+ (id)tupleWithFirst:(id)first second:(id)second {
- return [[[FPTuple alloc] initWithFirst:first second:second] autorelease];
+ return [[FPTuple alloc] initWithFirst:first second:second];
}
-- (void) dealloc
-{
- self.fst = nil;
- self.snd = nil;
- [super dealloc];
-}
-@end
+@end
View
0 ...FoundationAdditions/NSArray+FPAdditions.h → CoreFoundation/NSArray/NSArray+FPAdditions.h
File renamed without changes.
View
4 ...FoundationAdditions/NSArray+FPAdditions.m → CoreFoundation/NSArray/NSArray+FPAdditions.m
@@ -19,7 +19,7 @@ - (NSArray *)mapWithBlock:(id (^)(id obj))block {
if(mappedVal)
[result addObject:mappedVal];
}
- return [result autorelease];
+ return result;
}
- (NSArray *)zipWithArray:(NSArray *)otherArray {
@@ -36,7 +36,7 @@ - (NSArray *)zipWithArray:(NSArray *)otherArray {
[result addObject:zipped];
}
- return [result autorelease];
+ return result;
}
- (id)firstObject {
View
43 CoreFoundation/NSData/NSData+Base64.h
@@ -0,0 +1,43 @@
+//
+// NSData+Base64.h
+// base64
+//
+// Created by Matt Gallagher on 2009/06/03.
+// Copyright 2009 Matt Gallagher. All rights reserved.
+//
+// This software is provided 'as-is', without any express or implied
+// warranty. In no event will the authors be held liable for any damages
+// arising from the use of this software. Permission is granted to anyone to
+// use this software for any purpose, including commercial applications, and to
+// alter it and redistribute it freely, subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented; you must not
+// claim that you wrote the original software. If you use this software
+// in a product, an acknowledgment in the product documentation would be
+// appreciated but is not required.
+// 2. Altered source versions must be plainly marked as such, and must not be
+// misrepresented as being the original software.
+// 3. This notice may not be removed or altered from any source
+// distribution.
+//
+
+#import <Foundation/Foundation.h>
+
+void *NewBase64Decode(
+ const char *inputBuffer,
+ size_t length,
+ size_t *outputLength);
+
+char *NewBase64Encode(
+ const void *inputBuffer,
+ size_t length,
+ bool separateLines,
+ size_t *outputLength);
+
+@interface NSData (Base64)
+
++ (NSData *)dataFromBase64String:(NSString *)aString;
+- (NSString *)base64EncodedString;
+
+@end
+
View
149 CoreFoundationAdditions/NSData+Base64.m → CoreFoundation/NSData/NSData+Base64.m
@@ -5,20 +5,30 @@
// Created by Matt Gallagher on 2009/06/03.
// Copyright 2009 Matt Gallagher. All rights reserved.
//
-// Permission is given to use this source code file, free of charge, in any
-// project, commercial or otherwise, entirely at your risk, with the condition
-// that any redistribution (in part or whole) of source code must retain
-// this copyright and permission notice. Attribution in compiled projects is
-// appreciated but not required.
+// This software is provided 'as-is', without any express or implied
+// warranty. In no event will the authors be held liable for any damages
+// arising from the use of this software. Permission is granted to anyone to
+// use this software for any purpose, including commercial applications, and to
+// alter it and redistribute it freely, subject to the following restrictions:
//
+// 1. The origin of this software must not be misrepresented; you must not
+// claim that you wrote the original software. If you use this software
+// in a product, an acknowledgment in the product documentation would be
+// appreciated but is not required.
+// 2. Altered source versions must be plainly marked as such, and must not be
+// misrepresented as being the original software.
+// 3. This notice may not be removed or altered from any source
+// distribution.
+//
+// Comments converted to be ARC compatible
#import "NSData+Base64.h"
//
// Mapping from 6 bit pattern to ASCII character.
//
static unsigned char base64EncodeLookup[65] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
//
// Definition for "masked-out" areas of the base64DecodeLookup mapping
@@ -61,34 +71,34 @@
// output buffer.
//
// inputBuffer - the source ASCII string for the decode
-// length - the length of the string or -1 (to specify strlen should be used)
-// outputLength - if not-NULL, on output will contain the decoded length
+// length - the length of the string or -1 (to specify strlen should be used)
+// outputLength - if not-NULL, on output will contain the decoded length
//
// returns the decoded buffer. Must be free'd by caller. Length is given by
-// outputLength.
+// outputLength.
//
void *NewBase64Decode(
- const char *inputBuffer,
- size_t length,
- size_t *outputLength)
+ const char *inputBuffer,
+ size_t length,
+ size_t *outputLength)
{
if (length == -1)
{
length = strlen(inputBuffer);
}
-
+
size_t outputBufferSize =
- ((length+BASE64_UNIT_SIZE-1) / BASE64_UNIT_SIZE) * BINARY_UNIT_SIZE;
+ ((length+BASE64_UNIT_SIZE-1) / BASE64_UNIT_SIZE) * BINARY_UNIT_SIZE;
unsigned char *outputBuffer = (unsigned char *)malloc(outputBufferSize);
-
+
size_t i = 0;
size_t j = 0;
- unsigned char accumulated[BASE64_UNIT_SIZE];
while (i < length)
{
//
// Accumulate 4 valid characters (ignore everything else)
//
+ unsigned char accumulated[BASE64_UNIT_SIZE];
size_t accumulateIndex = 0;
while (i < length)
{
@@ -97,23 +107,28 @@
{
accumulated[accumulateIndex] = decode;
accumulateIndex++;
-
+
if (accumulateIndex == BASE64_UNIT_SIZE)
{
break;
}
}
}
-
+
//
// Store the 6 bits from each of the 4 characters as 3 bytes
//
- outputBuffer[j] = (accumulated[0] << 2) | (accumulated[1] >> 4);
- outputBuffer[j + 1] = (accumulated[1] << 4) | (accumulated[2] >> 2);
- outputBuffer[j + 2] = (accumulated[2] << 6) | accumulated[3];
+ // (Uses improved bounds checking suggested by Alexandre Colucci)
+ //
+ if(accumulateIndex >= 2)
+ outputBuffer[j] = (accumulated[0] << 2) | (accumulated[1] >> 4);
+ if(accumulateIndex >= 3)
+ outputBuffer[j + 1] = (accumulated[1] << 4) | (accumulated[2] >> 2);
+ if(accumulateIndex >= 4)
+ outputBuffer[j + 2] = (accumulated[2] << 6) | accumulated[3];
j += accumulateIndex - 1;
}
-
+
if (outputLength)
{
*outputLength = j;
@@ -122,52 +137,52 @@
}
//
-// NewBase64Decode
+// NewBase64Encode
//
// Encodes the arbitrary data in the inputBuffer as base64 into a newly malloced
// output buffer.
//
// inputBuffer - the source data for the encode
-// length - the length of the input in bytes
+// length - the length of the input in bytes
// separateLines - if zero, no CR/LF characters will be added. Otherwise
-// a CR/LF pair will be added every 64 encoded chars.
-// outputLength - if not-NULL, on output will contain the encoded length
-// (not including terminating 0 char)
+// a CR/LF pair will be added every 64 encoded chars.
+// outputLength - if not-NULL, on output will contain the encoded length
+// (not including terminating 0 char)
//
// returns the encoded buffer. Must be free'd by caller. Length is given by
-// outputLength.
+// outputLength.
//
char *NewBase64Encode(
- const void *buffer,
- size_t length,
- bool separateLines,
- size_t *outputLength)
+ const void *buffer,
+ size_t length,
+ bool separateLines,
+ size_t *outputLength)
{
const unsigned char *inputBuffer = (const unsigned char *)buffer;
-
- #define MAX_NUM_PADDING_CHARS 2
- #define OUTPUT_LINE_LENGTH 64
- #define INPUT_LINE_LENGTH ((OUTPUT_LINE_LENGTH / BASE64_UNIT_SIZE) * BINARY_UNIT_SIZE)
- #define CR_LF_SIZE 2
-
+
+#define MAX_NUM_PADDING_CHARS 2
+#define OUTPUT_LINE_LENGTH 64
+#define INPUT_LINE_LENGTH ((OUTPUT_LINE_LENGTH / BASE64_UNIT_SIZE) * BINARY_UNIT_SIZE)
+#define CR_LF_SIZE 2
+
//
// Byte accurate calculation of final buffer size
//
size_t outputBufferSize =
- ((length / BINARY_UNIT_SIZE)
- + ((length % BINARY_UNIT_SIZE) ? 1 : 0))
- * BASE64_UNIT_SIZE;
+ ((length / BINARY_UNIT_SIZE)
+ + ((length % BINARY_UNIT_SIZE) ? 1 : 0))
+ * BASE64_UNIT_SIZE;
if (separateLines)
{
outputBufferSize +=
- (outputBufferSize / OUTPUT_LINE_LENGTH) * CR_LF_SIZE;
+ (outputBufferSize / OUTPUT_LINE_LENGTH) * CR_LF_SIZE;
}
-
+
//
// Include space for a terminating zero
//
outputBufferSize += 1;
-
+
//
// Allocate the output buffer
//
@@ -176,55 +191,55 @@
{
return NULL;
}
-
+
size_t i = 0;
size_t j = 0;
const size_t lineLength = separateLines ? INPUT_LINE_LENGTH : length;
size_t lineEnd = lineLength;
-
+
while (true)
{
if (lineEnd > length)
{
lineEnd = length;
}
-
+
for (; i + BINARY_UNIT_SIZE - 1 < lineEnd; i += BINARY_UNIT_SIZE)
{
//
// Inner loop: turn 48 bytes into 64 base64 characters
//
outputBuffer[j++] = base64EncodeLookup[(inputBuffer[i] & 0xFC) >> 2];
outputBuffer[j++] = base64EncodeLookup[((inputBuffer[i] & 0x03) << 4)
- | ((inputBuffer[i + 1] & 0xF0) >> 4)];
+ | ((inputBuffer[i + 1] & 0xF0) >> 4)];
outputBuffer[j++] = base64EncodeLookup[((inputBuffer[i + 1] & 0x0F) << 2)
- | ((inputBuffer[i + 2] & 0xC0) >> 6)];
+ | ((inputBuffer[i + 2] & 0xC0) >> 6)];
outputBuffer[j++] = base64EncodeLookup[inputBuffer[i + 2] & 0x3F];
}
-
+
if (lineEnd == length)
{
break;
}
-
+
//
// Add the newline
//
outputBuffer[j++] = '\r';
outputBuffer[j++] = '\n';
lineEnd += lineLength;
}
-
+
if (i + 1 < length)
{
//
// Handle the single '=' case
//
outputBuffer[j++] = base64EncodeLookup[(inputBuffer[i] & 0xFC) >> 2];
outputBuffer[j++] = base64EncodeLookup[((inputBuffer[i] & 0x03) << 4)
- | ((inputBuffer[i + 1] & 0xF0) >> 4)];
+ | ((inputBuffer[i + 1] & 0xF0) >> 4)];
outputBuffer[j++] = base64EncodeLookup[(inputBuffer[i + 1] & 0x0F) << 2];
- outputBuffer[j++] = '=';
+ outputBuffer[j++] = '=';
}
else if (i < length)
{
@@ -237,7 +252,7 @@
outputBuffer[j++] = '=';
}
outputBuffer[j] = 0;
-
+
//
// Set the output length and return the buffer
//
@@ -259,15 +274,14 @@ @implementation NSData (Base64)
// Parameters:
// aString - the base64 string to decode
//
-// returns the autoreleased NSData representation of the base64 string
+// returns the NSData representation of the base64 string
//
-+ (NSData *)dataFromBase64String: (NSString *)aString
++ (NSData *)dataFromBase64String:(NSString *)aString
{
- NSData *data = [aString dataUsingEncoding: NSASCIIStringEncoding];
+ NSData *data = [aString dataUsingEncoding:NSASCIIStringEncoding];
size_t outputLength;
void *outputBuffer = NewBase64Decode([data bytes], [data length], &outputLength);
- NSData *result = [NSData dataWithBytes: outputBuffer
- length: outputLength];
+ NSData *result = [NSData dataWithBytes:outputBuffer length:outputLength];
free(outputBuffer);
return result;
}
@@ -278,19 +292,16 @@ + (NSData *)dataFromBase64String: (NSString *)aString
// Creates an NSString object that contains the base 64 encoding of the
// receiver's data. Lines are broken at 64 characters long.
//
-// returns an autoreleased NSString being the base 64 representation of the
-// receiver.
+// returns an NSString being the base 64 representation of the
+// receiver.
//
- (NSString *)base64EncodedString
{
- size_t outputLength;
+ size_t outputLength = 0;
char *outputBuffer =
- NewBase64Encode([self bytes], [self length], true, &outputLength);
-
- NSString *result = [[[NSString alloc] initWithBytes: outputBuffer
- length: outputLength
- encoding: NSASCIIStringEncoding]
- autorelease];
+ NewBase64Encode([self bytes], [self length], true, &outputLength);
+
+ NSString *result = [[NSString alloc] initWithBytes:outputBuffer length:outputLength encoding:NSASCIIStringEncoding];
free(outputBuffer);
return result;
}
View
0 ...Additions/NSData+CocoaDevUsersAdditions.h → ...on/NSData/NSData+CocoaDevUsersAdditions.h
File renamed without changes.
View
0 ...Additions/NSData+CocoaDevUsersAdditions.m → ...on/NSData/NSData+CocoaDevUsersAdditions.m
File renamed without changes.
View
0 ...ndationAdditions/NSObject+KVCExtensions.h → ...ndation/NSObject/NSObject+KVCExtensions.h
File renamed without changes.
View
3 ...ndationAdditions/NSObject+KVCExtensions.m → ...ndation/NSObject/NSObject+KVCExtensions.m
@@ -8,6 +8,7 @@
#import "NSObject+KVCExtensions.h"
#import "NSArray+FPAdditions.h"
+#import "Util.h"
@implementation NSObject (KVCExtensions)
@@ -38,7 +39,7 @@ - (NSDictionary *)dictionaryWithValuesForKeyPaths:(NSArray *)keyPaths {
[dict setValue:[self valueForKeyPath:k] forKey:k];
}
- return [dict autorelease];
+ return dict;
}
@end
View
0 ...dationAdditions/NSObject+ObserveActions.h → ...dation/NSObject/NSObject+ObserveActions.h
File renamed without changes.
View
4 ...dationAdditions/NSObject+ObserveActions.m → ...dation/NSObject/NSObject+ObserveActions.m
@@ -51,7 +51,6 @@ - (void)deactivateBinding {
- (void) dealloc
{
[self deactivateBinding];
- [super dealloc];
}
@@ -69,22 +68,19 @@ - (void)addObserverAction:(ObserveAction)action forKeyPath:(NSString *)keyPath {
if(actions == nil) {
actions = [NSMutableDictionary new];
objc_setAssociatedObject(self, &observeActionKey, actions, OBJC_ASSOCIATION_RETAIN);
- [actions release];
}
ObserveActionBinding *binding = [[ObserveActionBinding alloc] initWithObservedObject:self keyPath:keyPath action:action];
ObserveActionBinding *prevBinding = [actions objectForKey:keyPath];
[prevBinding deactivateBinding]; // technically not necessary
[actions setObject:binding forKey:keyPath];
- [binding release];
}
- (void)removeActionObserverForKeyPath:(NSString *)keyPath {
NSMutableDictionary *actions = objc_getAssociatedObject(self, &observeActionKey);
if(actions == nil) {
actions = [NSMutableDictionary new];
objc_setAssociatedObject(self, &observeActionKey, actions, OBJC_ASSOCIATION_RETAIN);
- [actions release];
}
ObserveActionBinding *binding = [actions objectForKey:keyPath];
View
16 CoreFoundation/NSString/NSString+Hash.h
@@ -0,0 +1,16 @@
+//
+// NSString+Hash.h
+// Lists
+//
+// Created by Marcel Ruegenberg on 28.02.11.
+// Copyright 2011 Dustlab. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+
+@interface NSString (Hash)
+
+- (NSString *)sha1Hash;
+
+@end
View
24 CoreFoundation/NSString/NSString+Hash.m
@@ -0,0 +1,24 @@
+//
+// NSString+Hash.m
+// Lists
+//
+// Created by Marcel Ruegenberg on 28.02.11.
+// Copyright 2011 Dustlab. All rights reserved.
+//
+
+#import "NSString+Hash.h"
+#import "NSData+CocoaDevUsersAdditions.h"
+#import <CommonCrypto/CommonDigest.h>
+
+
+@implementation NSString (Hash)
+
+- (NSString *)sha1Hash {
+ NSData *theData = [self dataUsingEncoding:NSUTF8StringEncoding];
+ static uint8_t digest[CC_SHA1_DIGEST_LENGTH] = {0}; //static, because it can be reused
+ CC_SHA1(theData.bytes, theData.length, digest);
+ NSString *theHash = [[NSData dataWithBytes:digest length:CC_SHA1_DIGEST_LENGTH] base32String];
+ return theHash;
+}
+
+@end
View
0 ...ationAdditions/NSString+StringAdditions.h → ...ation/NSString/NSString+StringAdditions.h
File renamed without changes.
View
0 ...ationAdditions/NSString+StringAdditions.m → ...ation/NSString/NSString+StringAdditions.m
File renamed without changes.
View
0 ...ndationAdditions/NSURL+ParameterParsing.h → ...Foundation/Other/NSURL+ParameterParsing.h
File renamed without changes.
View
0 ...ndationAdditions/NSURL+ParameterParsing.m → ...Foundation/Other/NSURL+ParameterParsing.m
File renamed without changes.
View
33 CoreFoundationAdditions/NSData+Base64.h
@@ -1,33 +0,0 @@
-//
-// NSData+Base64.h
-// base64
-//
-// Created by Matt Gallagher on 2009/06/03.
-// Copyright 2009 Matt Gallagher. All rights reserved.
-//
-// Permission is given to use this source code file, free of charge, in any
-// project, commercial or otherwise, entirely at your risk, with the condition
-// that any redistribution (in part or whole) of source code must retain
-// this copyright and permission notice. Attribution in compiled projects is
-// appreciated but not required.
-//
-
-#import <Foundation/Foundation.h>
-
-void *NewBase64Decode(
- const char *inputBuffer,
- size_t length,
- size_t *outputLength);
-
-char *NewBase64Encode(
- const void *inputBuffer,
- size_t length,
- bool separateLines,
- size_t *outputLength);
-
-@interface NSData (Base64)
-
-+ (NSData *)dataFromBase64String: (NSString *)aString;
-- (NSString *)base64EncodedString;
-
-@end
View
15 CoreFoundationAdditions/NSString+PercentEscape.h
@@ -1,15 +0,0 @@
-//
-// NSString+PercentEscape.h
-//
-// Created by Yevhene Shemet on 10.08.10.
-// Copyright Componentix 2010. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
-
-
-@interface NSString (PercentEscape)
-
-- (NSString *)stringWithPercentEscape;
-
-@end
View
23 CoreFoundationAdditions/NSString+PercentEscape.m
@@ -1,23 +0,0 @@
-//
-// NSString+Escape.m
-//
-// Created by Yevhene Shemet on 10.08.10.
-// Copyright Componentix 2010. All rights reserved.
-//
-
-
-#import "NSString+PercentEscape.h"
-
-
-@implementation NSString (PercentEscape)
-
-- (NSString *)stringWithPercentEscape {
- return [(NSString *)CFURLCreateStringByAddingPercentEscapes(
- NULL,
- (CFStringRef)[[self mutableCopy] autorelease],
- NULL,
- CFSTR("=,!$&'()*+;@?\n\"<>#\t :/"),
- kCFStringEncodingUTF8) autorelease];
-}
-
-@end
View
14 CoreFoundationAdditions/TimeHelpers.h
@@ -1,14 +0,0 @@
-//
-// TimeHelpers.h
-// Checklists
-//
-// Created by Marcel Ruegenberg on 06.02.11.
-// Copyright 2011 Dustlab. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
-
-/**
- Convert a time interval (in seconds) to a string of the form "5 days, 3 hours, 2 minutes before"
- */
-NSString *timeIntervalToString(NSInteger timeInterval);
View
23 CoreFoundationAdditions/TimeHelpers.m
@@ -1,23 +0,0 @@
-//
-// TimeHelpers.m
-// Checklists
-//
-// Created by Marcel Ruegenberg on 06.02.11.
-// Copyright 2011 Dustlab. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
-
-
-// time interval in seconds
-NSString *timeIntervalToString(NSInteger timeInterval) {
- if(timeInterval == 0) return @"None";
-
- NSString *prefix = @"";
- NSString *suffix = timeInterval < 0 ? @"before" : @"after";
- if(timeInterval < 0) timeInterval = timeInterval * (-1);
- if(timeInterval > 60 * 60 * 24) prefix = [NSString stringWithFormat:@"%d days", (timeInterval / (60 * 60 * 24))];
- else if(timeInterval > 60 * 60) prefix = [NSString stringWithFormat:@"%d hours", (timeInterval / (60 * 60))];
- else prefix = [NSString stringWithFormat:@"%d minutes", (timeInterval / 60)];
- return [NSString stringWithFormat:@"%@ %@", prefix, suffix];
-}
View
303 CoreGraphicsUtils/PathUtils.c
@@ -1,303 +0,0 @@
-//
-// PUPathUtils.c
-// Background
-//
-// Created by Yevhene Shemet on 30.08.11.
-//
-
-#include "PathUtils.h"
-
-#include <stdlib.h>
-
-#include <math.h>
-
-#define TAU 0.5
-
-#pragma mark =
-#pragma mark PathLength
-
-typedef struct {
- CGPoint startPoint;
- CGFloat length;
- CGPoint lastPoint;
-} PUPathLengthApplierFunctionInfo;
-
-
-void PUPathElementLengthApplierFunction(void *info, const CGPathElement *element)
-{
- PUPathLengthApplierFunctionInfo *pathLengthInfo = (PUPathLengthApplierFunctionInfo *)info;
- switch (element->type) {
- case kCGPathElementMoveToPoint:
- // points[0] - destination point.
- pathLengthInfo->startPoint = element->points[0];
- pathLengthInfo->lastPoint = pathLengthInfo->startPoint;
- break;
- case kCGPathElementAddLineToPoint:
- // points[0] - destination point.
- pathLengthInfo->length += PULineLength(pathLengthInfo->lastPoint,
- element->points[0]);
- pathLengthInfo->lastPoint = element->points[0];
- break;
- case kCGPathElementAddQuadCurveToPoint:
- // points[0] - control point 1.
- // points[1] - destination point.
- pathLengthInfo->length += PUQuadraticBezierCurveLength(pathLengthInfo->lastPoint,
- element->points[0],
- element->points[1]);
- pathLengthInfo->lastPoint = element->points[1];
- break;
- case kCGPathElementAddCurveToPoint:
- // points[0] - control point 1.
- // points[1] - control point 2.
- // points[2] - destination point.
- pathLengthInfo->length += PUCubicBezierCurveLength(pathLengthInfo->lastPoint,
- element->points[0],
- element->points[1],
- element->points[2]);
- pathLengthInfo->lastPoint = element->points[2];
- break;
- case kCGPathElementCloseSubpath:
- // no points.
- if (!CGPointEqualToPoint(pathLengthInfo->lastPoint,
- pathLengthInfo->startPoint)) {
- pathLengthInfo->length += PULineLength(pathLengthInfo->lastPoint,
- pathLengthInfo->startPoint);
- }
- pathLengthInfo->lastPoint = pathLengthInfo->startPoint;
- break;
- }
-}
-
-CGFloat PUPathLength(CGPathRef path)
-{
- PUPathLengthApplierFunctionInfo info;
- info.startPoint = CGPointZero;
- info.length = 0;
- info.lastPoint = CGPointZero;
- CGPathApply(path, &info, PUPathElementLengthApplierFunction);
- return info.length;
-}
-
-
-#pragma mark =
-#pragma mark TracePath
-
-typedef struct {
- CGPoint startPoint;
- CGFloat lengthLeft;
- CGPoint lastPoint;
- CGPoint result;
- bool isFound;
-} PUTracePathApplierFunctionInfo;
-
-
-void PUPathElementTraceApplierFunction(void *info, const CGPathElement *element)
-{
- PUTracePathApplierFunctionInfo *tracePathInfo = (PUTracePathApplierFunctionInfo *)info;
- if (tracePathInfo->isFound) {
- return;
- }
- CGFloat pathElementLength = 0;
- switch (element->type) {
- case kCGPathElementMoveToPoint:
- // points[0] - destination point.
- tracePathInfo->startPoint = element->points[0];
- tracePathInfo->lastPoint = tracePathInfo->startPoint;
- tracePathInfo->result = tracePathInfo->lastPoint;
- break;
- case kCGPathElementAddLineToPoint:
- // points[0] - destination point.
- pathElementLength = PULineLength(tracePathInfo->lastPoint, element->points[0]);
- if (tracePathInfo->lengthLeft < pathElementLength) {
- tracePathInfo->result = PULinePoint(tracePathInfo->lengthLeft / pathElementLength,
- tracePathInfo->lastPoint,
- element->points[0]);
- tracePathInfo->lengthLeft = 0;
- tracePathInfo->isFound = true;
- } else {
- tracePathInfo->lastPoint = element->points[0];
- tracePathInfo->lengthLeft -= pathElementLength;
- }
- break;
- case kCGPathElementAddQuadCurveToPoint:
- // points[0] - control point 1.
- // points[1] - destination point.
- pathElementLength = PUQuadraticBezierCurveLength(tracePathInfo->lastPoint,
- element->points[0],
- element->points[1]);
- if (tracePathInfo->lengthLeft < pathElementLength) {
- tracePathInfo->result = PUQuadraticBezierCurvePoint(tracePathInfo->lengthLeft / pathElementLength,
- tracePathInfo->lastPoint,
- element->points[0],
- element->points[1]);
- tracePathInfo->lengthLeft = 0;
- tracePathInfo->isFound = true;
- } else {
- tracePathInfo->lastPoint = element->points[1];
- tracePathInfo->lengthLeft -= pathElementLength;
- }
- break;
- case kCGPathElementAddCurveToPoint:
- // points[0] - control point 1.
- // points[1] - control point 2.
- // points[2] - destination point.
- pathElementLength = PUCubicBezierCurveLength(tracePathInfo->lastPoint,
- element->points[0],
- element->points[1],
- element->points[2]);
- if (tracePathInfo->lengthLeft < pathElementLength) {
- tracePathInfo->result = PUCubicBezierCurvePoint(tracePathInfo->lengthLeft / pathElementLength,
- tracePathInfo->lastPoint,
- element->points[0],
- element->points[1],
- element->points[2]);
- tracePathInfo->lengthLeft = 0;
- tracePathInfo->isFound = true;
- } else {
- tracePathInfo->lastPoint = element->points[2];
- tracePathInfo->lengthLeft -= pathElementLength;
- }
- break;
- case kCGPathElementCloseSubpath:
- // no points.
- if (!CGPointEqualToPoint(tracePathInfo->lastPoint,
- tracePathInfo->startPoint)) {
- pathElementLength = PULineLength(tracePathInfo->lastPoint, tracePathInfo->startPoint);
- if (tracePathInfo->lengthLeft < pathElementLength) {
- tracePathInfo->result = PULinePoint(tracePathInfo->lengthLeft / pathElementLength,
- tracePathInfo->lastPoint,
- tracePathInfo->startPoint);
- tracePathInfo->lengthLeft = 0;
- tracePathInfo->isFound = true;
- } else {
- tracePathInfo->lastPoint = element->points[0];
- tracePathInfo->lengthLeft -= pathElementLength;
- }
- }
- break;
- }
-}
-
-CGPoint PUTracePath(CGPathRef path, CGFloat length)
-{
- PUTracePathApplierFunctionInfo info;
- info.startPoint = CGPointZero;
- info.lengthLeft = length;
- info.lastPoint = CGPointZero;
- info.result = CGPointZero;
- info.isFound = false;
- CGPathApply(path, &info, PUPathElementTraceApplierFunction);
- return info.result;
-}
-
-
-#pragma mark =
-#pragma mark TransformedPath
-
-CGPathRef PUTransformPath(CGPathRef path,
- int numberOfChunks,
- void (^fillChunk)(CGMutablePathRef newPath, CGPoint pointFrom, CGPoint pointTo))
-{
- CGMutablePathRef transformedPath = CGPathCreateMutable();
- CGPoint firstPoint = PUTracePath(path, 0);
- CGPathMoveToPoint(transformedPath, NULL, firstPoint.x, firstPoint.y);
-
- CGFloat pathLength = PUPathLength(path);
- CGFloat chunkLength = pathLength / numberOfChunks;
- CGPoint pointFrom = CGPointZero;
- CGPoint pointTo = firstPoint;
- for (int i = 0; i < numberOfChunks - 1; ++i) {
- pointFrom = pointTo;
- pointTo = PUTracePath(path, (i+1)*chunkLength);
- fillChunk(transformedPath, pointFrom, pointTo);
- }
- fillChunk(transformedPath, pointTo, firstPoint);
-
- return transformedPath;
-}
-
-#pragma mark =
-#pragma mark Utils
-
-CGPoint PULinePoint(double t, CGPoint from, CGPoint to)
-{
- CGPoint point;
- point.x = from.x + t * (to.x - from.x);
- point.y = from.y + t * (to.y - from.y);
- return point;
-}
-
-CGPoint PUQuadraticBezierCurvePoint(double t, CGPoint from, CGPoint control, CGPoint to)
-{
- CGPoint point;
- point.x = pow(1-t, 2)*from.x + 2*(1-t)*t*control.x + pow(t, 2)*to.x;
- point.y = pow(1-t, 2)*from.y + 2*(1-t)*t*control.y + pow(t, 2)*to.y;
- return point;
-}
-
-CGPoint PUCubicBezierCurvePoint(double t, CGPoint from, CGPoint control1, CGPoint control2, CGPoint to)
-{
- CGPoint point;
- point.x = pow(1-t, 3)*from.x + 3*pow(1-t, 2)*t*control1.x + 3*(1-t)*pow(t, 2)*control2.x + pow(t, 3)*to.x;
- point.y = pow(1-t, 3)*from.y + 3*pow(1-t, 2)*t*control1.y + 3*(1-t)*pow(t, 2)*control2.y + pow(t, 3)*to.y;
- return point;
-}
-
-CGFloat PULineLength(CGPoint from, CGPoint to)
-{
- return sqrt(pow((to.x - from.x), 2) +
- pow((to.y - from.y), 2));
-}
-
-CGFloat PUFunctionLength(CGPoint (^f)(double), double tStep)
-{
- CGFloat length = 0;
-
- CGPoint point0;
- CGPoint point1 = f(0);
-
- for (double t = 0; t <= 1; t += tStep) {
- point0 = point1;
- point1 = f(t);
- length += PULineLength(point0, point1);
- }
-
- return length;
-}
-
-CGFloat PUQuadraticBezierCurveLength(CGPoint from, CGPoint control, CGPoint to)
-{
- float length = PUFunctionLength(^CGPoint(double t) {
- return PUQuadraticBezierCurvePoint(t, from, control, to);
- }, 0.001);
-
- return length;
-}
-
-CGFloat PUCubicBezierCurveLength(CGPoint from, CGPoint control1, CGPoint control2, CGPoint to)
-{
- float length = PUFunctionLength(^CGPoint(double t) {
- return PUCubicBezierCurvePoint(t, from, control1, control2, to);
- }, 0.001);
-
- return length;
-}
-
-
-// Approximation from: http://segfaultlabs.com/docs/quadratic-bezier-curve-length
-/*CGFloat QuadraticBezierCurveLength(CGPoint from, CGPoint control, CGPoint to)
- {
- CGPoint a,b;
- a.x = from.x - 2*control.x + to.x;
- a.y = from.y - 2*control.y + to.y;
- b.x = 2*control.x - 2*from.x;
- b.y = 2*control.y - 2*from.y;
- float A = 4*(a.x*a.x + a.y*a.y);
- float B = 4*(a.x*b.x + a.y*b.y);
- float C = b.x*b.x + b.y*b.y;
-
- float length = ( (2*A+B)*sqrt(A+B+C) - B*sqrt(C) )/( 4 * A ) +
- ( 4*A*C-B*B) / (8*pow(A, 3.0/2.0) ) * log( (2*A+B+2*sqrt(A)*sqrt(A+B+C)) / (B+2*sqrt(A*C)) );
-
- return length;
- }*/
View
44 CoreGraphicsUtils/PathUtils.h
@@ -1,44 +0,0 @@
-//
-// PUPathUtils.h
-// PathUtils
-//
-// Created by Yevhene Shemet on 30.08.11.
-//
-
-#ifndef PUPathUtils_h
-#define PUPathUtils_h
-
-#include <CoreGraphics/CoreGraphics.h>
-
-/*
- * Returns path length.
- */
-CGFloat PUPathLength(CGPathRef path);
-
-/*
- * Returns point from path.
- */
-CGPoint PUTracePath(CGPathRef path, CGFloat length);
-
-/*
- * Returns new path, transformed by fillChunk.
- */
-CGPathRef PUTransformPath(CGPathRef path,
- int numberOfChunks,
- void (^fillChunk)(CGMutablePathRef newPath, CGPoint pointFrom, CGPoint pointTo));
-
-// Utils
-CGPoint PULinePoint(double t, CGPoint from, CGPoint to);
-
-CGPoint PUQuadraticBezierCurvePoint(double t, CGPoint from, CGPoint control, CGPoint to);
-
-CGPoint PUCubicBezierCurvePoint(double t, CGPoint from, CGPoint control1, CGPoint control2, CGPoint to);
-
-
-CGFloat PULineLength(CGPoint from, CGPoint to);
-
-CGFloat PUQuadraticBezierCurveLength(CGPoint from, CGPoint control, CGPoint to);
-
-CGFloat PUCubicBezierCurveLength(CGPoint from, CGPoint control1, CGPoint control2, CGPoint to);
-
-#endif
View
25 DLFolding.h
@@ -1,25 +0,0 @@
-//
-// DLFolding.h
-// CheckLists
-//
-// Created by Marcel Ruegenberg on 30.11.10.
-// Copyright 2010 Dustlab. All rights reserved.
-//
-
-#import <UIKit/UIKit.h>
-
-
-/**
- This protocol implements a fold mechanism, known from functional programming languages;
- You probably want a tail-optimizing compiler when using this.
- */
-@protocol DLFolding <NSObject>
-
-- (id)dl_foldWithAction:(id (^)(id acc, id val))action accumulator:(id)acc;
-
-/**
- Fold on all children and accumulate the results, but leave out the root element.
- */
-- (id)dl_foldOnChildrenWithAction:(id (^)(id acc, id val))action accumulator:(id)acc;
-
-@end
View
6 README.mdown
@@ -6,7 +6,11 @@ What is in here
---------------
- Various categories to make the standard CoreFoundation and UIKit classes more useful
- A few helper classes with the same purpose
-- The simple bindings-like mechanism has moved to its own repository <a href="https://github.com/mruegenberg/objc-simple-bindings">objc-simple-bindings</a>
+
+Compatibility
+-------------
+- As of version 0.2.0, all code requires an ARC (Automatic Reference Counting) capable compiler.
+- Everything should be compatible with the iOS SDK 5 or above
How to use
----------
View
68 SynthesizeSingleton.h
@@ -1,68 +0,0 @@
-//
-// SynthesizeSingleton.h
-// CocoaWithLove
-//
-// Created by Matt Gallagher on 20/10/08.
-// Copyright 2009 Matt Gallagher. All rights reserved.
-//
-// Permission is given to use this source code file without charge in any
-// project, commercial or otherwise, entirely at your risk, with the condition
-// that any redistribution (in part or whole) of source code must retain
-// this copyright and permission notice. Attribution in compiled projects is
-// appreciated but not required.
-//
-
-#define SYNTHESIZE_SINGLETON_FOR_CLASS(classname) \
- \
-static classname *shared##classname = nil; \
- \
-+ (classname *)shared##classname \
-{ \
- @synchronized(self) \
- { \
- if (shared##classname == nil) \
- { \
- shared##classname = [[self alloc] init]; \
- } \
- } \
- \
- return shared##classname; \
-} \
- \
-+ (id)allocWithZone:(NSZone *)zone \
-{ \
- @synchronized(self) \
- { \
- if (shared##classname == nil) \
- { \
- shared##classname = [super allocWithZone:zone]; \
- return shared##classname; \
- } \
- } \
- \
- return nil; \
-} \
- \
-- (id)copyWithZone:(NSZone *)zone \
-{ \
- return self; \
-} \
- \
-- (id)retain \
-{ \
- return self; \
-} \
- \
-- (NSUInteger)retainCount \
-{ \
- return NSUIntegerMax; \
-} \
- \
-- (oneway void)release \
-{ \
-} \
- \
-- (id)autorelease \
-{ \
- return self; \
-}
View
6 UIKitUtils/PopoverManager.h → UIKit/Controls/PopoverManager.h
@@ -6,18 +6,18 @@
// Copyright 2011 Dustlab. All rights reserved.
//
-#import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
/**
- A class for managing the retaining of popovers in a central place.
+ A class for managing the ownership of popovers in a central place.
Because even though Apple basically tells you to have only one popover at a time, they make it surprisingly hard to do this properly.
*/
@interface PopoverManager : NSObject {
UIPopoverController *currentPopoverController;
}
-@property (nonatomic, retain) UIPopoverController *currentPopoverController;
+@property (nonatomic, strong) UIPopoverController *currentPopoverController;
+ (PopoverManager *)sharedPopoverManager;
View
11 UIKitUtils/PopoverManager.m → UIKit/Controls/PopoverManager.m
@@ -7,7 +7,6 @@
//
#import "PopoverManager.h"
-#import "SynthesizeSingleton.h"
@interface PopoverManager ()
- (void)didReceiveMemoryWarning:(NSNotification *)notification;
@@ -16,7 +15,11 @@ - (void)didReceiveMemoryWarning:(NSNotification *)notification;
@implementation PopoverManager
@synthesize currentPopoverController;
-SYNTHESIZE_SINGLETON_FOR_CLASS(PopoverManager);
++ (PopoverManager *)sharedPopoverManager {
+ static PopoverManager *sharedPopoverManager;
+ if(sharedPopoverManager == nil) sharedPopoverManager = [PopoverManager new];
+ return sharedPopoverManager;
+}
- (id)init {
if((self = [super init])) {
@@ -34,8 +37,7 @@ - (void)setCurrentPopoverController:(UIPopoverController *)thePopoverController
#endif
[currentPopoverController dismissPopoverAnimated:NO]; // no animation when dismissing because this should not happen
}
- [currentPopoverController release];
- currentPopoverController = [thePopoverController retain];
+ currentPopoverController = thePopoverController;
}
}
@@ -48,7 +50,6 @@ - (void)didReceiveMemoryWarning:(NSNotification *)notification {
- (void) dealloc
{
self.currentPopoverController = nil;
- [super dealloc];
}
View
4 UIKitUtils/UIPlaceHolderTextView.h → UIKit/Controls/UIPlaceholderTextView.h
@@ -2,10 +2,12 @@
// from http://stackoverflow.com/questions/1328638/placeholder-in-uitextview
+#import <UIKit/UIKit.h>
+
@interface UIPlaceHolderTextView : UITextView
@property (nonatomic, copy) NSString *placeholder;
-@property (nonatomic, retain) UIColor *placeholderColor;
+@property (nonatomic, strong) UIColor *placeholderColor;
@end
View
6 UIKitUtils/UIPlaceHolderTextView.m → UIKit/Controls/UIPlaceholderTextView.m
@@ -2,7 +2,7 @@
@interface UIPlaceHolderTextView ()
-@property (nonatomic, retain) UILabel *placeHolderLabel;
+@property (nonatomic, strong) UILabel *placeHolderLabel;
-(void)textChanged:(NSNotification*)notification;
@@ -14,10 +14,6 @@ @implementation UIPlaceHolderTextView
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
- [placeHolderLabel release]; placeHolderLabel = nil;
- [placeholderColor release]; placeholderColor = nil;
- [placeholder release]; placeholder = nil;
- [super dealloc];
}
- (void)setup {
View
22 UIKit/Controls/UITabBarController+HideableTabBar.h
@@ -0,0 +1,22 @@
+//
+// UITabBarController+HideableTabBar.h
+// TBHidingTest
+//
+// Created by Marcel Ruegenberg on 11.06.11.
+// Copyright 2011 Dustlab. All rights reserved.
+//
+//
+
+#import <UIKit/UIKit.h>
+
+/* WARNING: The implementation of this category makes certain assumptions about the structure of the subviews of a UITabBarController's view. There is no guarantee for this to keep working from one version of iOS to the next.
+ In general, it is likely to be stable within at least major version of iOS.
+ Tested up to iOS 5.1.
+ */
+@interface UITabBarController (HideableTabBar)
+
+- (void)setTabBarHidden:(BOOL)hidden;
+
+- (void)setTabBarFlat:(BOOL)flat;
+
+@end
View
2 ...tions/UITabBarController+HideableTabBar.m → ...trols/UITabBarController+HideableTabBar.m
@@ -1,5 +1,5 @@
//
-// UITabBar+HidableTabBar.m
+// UITabBarController+HideableTabBar.m
// TBHidingTest
//
// Created by Marcel Ruegenberg on 11.06.11.
View
0 UIKitAdditions/InnerShadowDrawing.h → UIKit/Drawing/InnerShadowDrawing.h
File renamed without changes.
View
2 UIKitAdditions/InnerShadowDrawing.m → UIKit/Drawing/InnerShadowDrawing.m
@@ -74,4 +74,4 @@ void drawWithInnerShadow(CGRect rect,
// finally apply shadow
[innerShadow drawAtPoint:CGPointZero];
-}
+}
View
11 UIKitAdditions/UIColor+HelperAdditions.h → UIKit/Drawing/UIColor+HelperAdditions.h
@@ -6,8 +6,13 @@
// Copyright 2010 Dustlab. All rights reserved.
//
+#import <UIKit/UIKit.h>
+
@interface UIColor (HelperAdditions)
+/**
+ A color very close to the usual muted blue font color on iOS.
+ */
+ (UIColor *)prussianBlueColor;
/**
@@ -22,3 +27,9 @@
- (UIColor *)colorMultipliedByScalar:(CGFloat)scalar withMinimum:(CGFloat)min;
@end
+
+#define RGB(rVal, gVal, bVal) [UIColor colorWithRed:rVal green:gVal blue:bVal alpha:1.0]
+#define RGBA(rVal, gVal, bVal, aVal) [UIColor colorWithRed:rVal green:gVal blue:bVal alpha:aVal]
+#define HSB(hVal,sVal,bVal) [UIColor colorWithHue:hVal saturation:sVal brightness:bVal alpha:1.0]
+#define HSBA(hVal,sVal,bVal,aVal) [UIColor colorWithHue:hVal saturation:sVal brightness:bVal alpha:aVal]
+
View
0 UIKitAdditions/UIColor+HelperAdditions.m → UIKit/Drawing/UIColor+HelperAdditions.m
File renamed without changes.
View
2 UIKitAdditions/UIImage+Additions.h → UIKit/Drawing/UIImage+Additions.h
@@ -6,6 +6,8 @@
// Copyright 2010 Dustlab. All rights reserved.
//
+#import <UIKit/UIKit.h>
+
// from http://www.icab.de/blog/2010/10/01/scaling-images-and-creating-thumbnails-from-uiviews/
@interface UIImage (Scaling)
+ (UIImage*)imageFromView:(UIView*)view;
View
3 UIKitAdditions/UIImage+Additions.m → UIKit/Drawing/UIImage+Additions.m
@@ -48,7 +48,8 @@ + (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize
@implementation UIImage (Additions)
- (UIImage *)horizontallyStretchedImage {
- return [self stretchableImageWithLeftCapWidth:((self.size.width - 1) / 2.0) topCapHeight:0];
+ CGFloat s = ((self.size.width - 1) / 2.0);
+ return [self resizableImageWithCapInsets:UIEdgeInsetsMake(0, s, 0, s)];
}
@end
View
2 UIKitAdditions/UIKit+DrawingHelpers.h → UIKit/Drawing/UIKit+DrawingHelpers.h
@@ -6,6 +6,8 @@
// Copyright 2009 Dustlab. All rights reserved.
//
+#import <UIKit/UIKit.h>
+
void CGPathAddRoundedRect(CGMutablePathRef path, CGRect rect, CGFloat radius);
/**
View
31 UIKitAdditions/UIKit+DrawingHelpers.m → UIKit/Drawing/UIKit+DrawingHelpers.m
@@ -52,8 +52,8 @@ void CGContextClipToRoundedRect(CGContextRef c, CGRect rect, CGFloat radius) {
void DL_CGContextDrawLinearGradient(CGContextRef context, NSArray *colors, const CGFloat locations[], CGPoint startPoint, CGPoint endPoint) {
CGColorSpaceRef myColorspace = CGColorSpaceCreateDeviceRGB();
NSMutableArray *arr = [NSMutableArray arrayWithCapacity:[colors count]];
- for(UIColor *c in colors) { [arr addObject:(id)[c CGColor]]; }
- CGGradientRef gradient = CGGradientCreateWithColors(myColorspace, (CFArrayRef)arr, locations);
+ for(UIColor *c in colors) { [arr addObject:(__bridge id)[c CGColor]]; }
+ CGGradientRef gradient = CGGradientCreateWithColors(myColorspace, (__bridge CFArrayRef)arr, locations);
CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
@@ -68,33 +68,30 @@ void DL_CGContextDrawLinearGradientOverRect(CGContextRef context, NSArray *color
void DL_CGContextDrawSteelGradientOverRect(CGContextRef context, CGRect rect) {
CGFloat locations[4] = { 0.0, 0.015, 0.985, 1.0 };
DL_CGContextDrawLinearGradientOverRect(context,
- [NSArray arrayWithObjects:
- [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0],
- [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0],
- [UIColor colorWithRed:0.7 green:0.7 blue:0.7 alpha:1.0],
- [UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:1.0],nil],
+ @[[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0],
+ [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0],
+ [UIColor colorWithRed:0.7 green:0.7 blue:0.7 alpha:1.0],
+ [UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:1.0]],
locations, rect);
}
void DL_CGContextDrawLightSteelGradientOverRect(CGContextRef context, CGRect rect) {
CGFloat locations[4] = { 0.0, 0.025, 0.985, 1.0 };
DL_CGContextDrawLinearGradientOverRect(context,
- [NSArray arrayWithObjects:
- [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0],
- [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.0],
- [UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1.0],
- [UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:1.0],nil],
+ @[[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0],
+ [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.0],
+ [UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1.0],
+ [UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:1.0]],
locations, rect);
}
void DL_CGContextDrawHighlightsOverRect(CGContextRef context, CGRect rect) {
CGFloat locations[4] = { 0.0, 0.02, 0.98, 1.0 };
DL_CGContextDrawLinearGradientOverRect(context,
- [NSArray arrayWithObjects:
- [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0],
- [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.0],
- [UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:0.0],
- [UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:1.0],nil],
+ @[[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0],
+ [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.0],
+ [UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:0.0],
+ [UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:1.0]],
locations, rect);
}
View
4 UIKitAdditions/UIControl+DLBlockAdditions.h → UIKit/Utility/UIControl+DLBlockAdditions.h
@@ -6,6 +6,8 @@
// Copyright 2011 Dustlab. All rights reserved.
//
+#import <UIKit/UIKit.h>
+
typedef void(^DLControlAction)(id sender);
@interface UIControl (UIControl_DLBlockAdditions)
@@ -15,4 +17,6 @@ typedef void(^DLControlAction)(id sender);
*/
- (void)addAction:(DLControlAction)actionBlock forControlEvents:(UIControlEvents)controlEvents;
+- (void)cleanup;
+
@end
View
16 UIKitAdditions/UIControl+DLBlockAdditions.m → UIKit/Utility/UIControl+DLBlockAdditions.m
@@ -23,10 +23,6 @@ - (void)invoke:(id)sender {
self.block(sender);
}
-- (void)dealloc {
- self.block = nil;
- [super dealloc];
-}
@end
@@ -42,7 +38,6 @@ - (void)addAction:(DLControlAction)actionBlock forControlEvents:(UIControlEvents
if(actions == nil) {
actions = [NSMutableArray new];
objc_setAssociatedObject(self, &actionKey, actions, OBJC_ASSOCIATION_RETAIN);
- [actions release];
}
if(actions == nil) actions = [NSMutableArray new];
@@ -51,7 +46,16 @@ - (void)addAction:(DLControlAction)actionBlock forControlEvents:(UIControlEvents
wrapper.block = actionBlock;
[self addTarget:wrapper action:@selector(invoke:) forControlEvents:controlEvents];
[actions addObject:wrapper];
- [wrapper release];
+}
+
+- (void)cleanup {
+ NSMutableArray *actions = objc_getAssociatedObject(self, &actionKey);
+ if(actions == nil) return;
+ for(DLBlockWrapper *actionWrapper in actions) {
+ actionWrapper.block = nil;
+ }
+ [actions removeAllObjects];
+ objc_setAssociatedObject(self, &actionKey, nil, OBJC_ASSOCIATION_RETAIN);
}
@end
View
16 UIKit/Utility/UIDeviceHardware.h
@@ -0,0 +1,16 @@
+//
+// UIDeviceHardware.h
+// Classes
+//
+// Created by Marcel Ruegenberg on 03.04.12.
+// Copyright (c) 2012 Dustlab. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface UIDeviceHardware : NSObject
+
++ (NSString *) platform;
++ (NSString *) platformString;
+
+@end
View
49 UIKit/Utility/UIDeviceHardware.m
@@ -0,0 +1,49 @@
+//
+// UIDeviceHardware.m
+// Classes
+//
+// Created by Marcel Ruegenberg on 03.04.12.
+// Copyright (c) 2012 Dustlab. All rights reserved.
+//
+
+#import "UIDeviceHardware.h"
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
+@implementation UIDeviceHardware
+
++ (NSString *)platform{
+ size_t size;
+ sysctlbyname("hw.machine", NULL, &size, NULL, 0);
+ char *machine = malloc(size);
+ sysctlbyname("hw.machine", machine, &size, NULL, 0);
+ NSString *platform = [NSString stringWithUTF8String:machine];
+ free(machine);
+ return platform;
+}
+
++ (NSString *)platformString{
+ NSString *platform = [UIDeviceHardware platform];
+ if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 1G";
+ if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
+ if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
+ if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4";
+ if ([platform isEqualToString:@"iPhone3,3"]) return @"Verizon iPhone 4";
+ if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone 4S";
+ if ([platform isEqualToString:@"iPod1,1"]) return @"iPod Touch 1G";
+ if ([platform isEqualToString:@"iPod2,1"]) return @"iPod Touch 2G";
+ if ([platform isEqualToString:@"iPod3,1"]) return @"iPod Touch 3G";
+ if ([platform isEqualToString:@"iPod4,1"]) return @"iPod Touch 4G";
+ if ([platform isEqualToString:@"iPad1,1"]) return @"iPad";
+ if ([platform isEqualToString:@"iPad2,1"]) return @"iPad 2 (WiFi)";
+ if ([platform isEqualToString:@"iPad2,2"]) return @"iPad 2 (GSM)";
+ if ([platform isEqualToString:@"iPad2,3"]) return @"iPad 2 (CDMA)";
+ if ([platform isEqualToString:@"iPad3,1"]) return @"iPad-3G (WiFi)";
+ if ([platform isEqualToString:@"iPad3,2"]) return @"iPad-3G (4G)";
+ if ([platform isEqualToString:@"iPad3,3"]) return @"iPad-3G (4G)";
+ if ([platform isEqualToString:@"i386"]) return @"Simulator";
+ if ([platform isEqualToString:@"x86_64"]) return @"Simulator";
+ return platform;
+}
+
+@end
View
15 UIKit/ViewUtil/UIKitHelpers.h
@@ -0,0 +1,15 @@
+//
+// UIKitHelpers.h
+// Classes
+//
+// Created by Marcel Ruegenberg on 13.06.11.
+// Copyright 2011 Dustlab. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+UIButton *deleteButtonWithTitle(NSString *title);
+
+void displayInfoAlert(NSString *message);
+
+CGSize contentSizeForTableViewController(UITableViewController *controller, CGFloat minHeight);
View
52 UIKit/ViewUtil/UIKitHelpers.m
@@ -0,0 +1,52 @@
+//
+// UIKitHelpers.m
+// Classes
+//
+// Created by Marcel Ruegenberg on 13.06.11.
+// Copyright 2011 Dustlab. All rights reserved.
+//
+
+#import "UIKitHelpers.h"
+
+
+UIButton *deleteButtonWithTitle(NSString *title) {
+ UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
+
+ deleteButton.frame = CGRectMake(0, 0, 300, 40);
+ [deleteButton setTitle:title forState:UIControlStateNormal];
+
+ UIImage *deleteButtonBG = [[UIImage imageNamed:@"delete_button.png"] stretchableImageWithLeftCapWidth:9 topCapHeight:0];
+ [deleteButton setBackgroundImage:deleteButtonBG forState:UIControlStateNormal];
+ deleteButton.titleLabel.font = [UIFont boldSystemFontOfSize:18.0];
+
+ [deleteButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
+ [deleteButton setTitleShadowColor:[UIColor colorWithRed:0.5 green:0 blue:0 alpha:1.0] forState:UIControlStateNormal];
+
+ deleteButton.titleLabel.shadowOffset = CGSizeMake(0, -1);
+
+ return deleteButton;
+}
+
+void displayInfoAlert(NSString *message) {
+ static UIAlertView *currentAlert = nil;
+ currentAlert = [[UIAlertView alloc] initWithTitle:message message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
+ [currentAlert show];
+}
+
+CGSize contentSizeForTableViewController(UITableViewController *controller, CGFloat minHeight) {
+ CGFloat totalHeight = controller.tableView.sectionHeaderHeight;
+ NSUInteger sC = [controller numberOfSectionsInTableView:controller.tableView];
+ for(NSUInteger s = 0; s < sC; ++s) {
+ totalHeight += [controller respondsToSelector:@selector(tableView:heightForHeaderInSection:)] ? [controller tableView:controller.tableView heightForHeaderInSection:s] : controller.tableView.sectionHeaderHeight;
+ NSUInteger rC = [controller tableView:controller.tableView numberOfRowsInSection:s];
+ if([controller respondsToSelector:@selector(tableView:heightForRowAtIndexPath:)]) {
+ for(NSUInteger r = 0; r < rC; ++r)
+ totalHeight += [controller tableView:controller.tableView heightForRowAtIndexPath:[NSIndexPath indexPathForRow:r inSection:s]];
+ }
+ else {
+ totalHeight += rC * controller.tableView.rowHeight;
+ }
+ totalHeight += [controller respondsToSelector:@selector(tableView:heightForFooterInSection:)] ? [controller tableView:controller.tableView heightForFooterInSection:s] : controller.tableView.sectionFooterHeight;
+ }
+ return CGSizeMake(320, MAX(minHeight, totalHeight));
+}
View
0 UIKitAdditions/UIView+Additions.h → UIKit/ViewUtil/UIView+Additions.h
File renamed without changes.
View
0 UIKitAdditions/UIView+Additions.m → UIKit/ViewUtil/UIView+Additions.m
File renamed without changes.
View
BIN UIKit/ViewUtil/delete_button.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN UIKit/ViewUtil/delete_button@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN UIKit/ViewUtil/light_button.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN UIKit/ViewUtil/light_button@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
25 UIKitAdditions/UIImage+Resize.h
@@ -1,25 +0,0 @@
-// UIImage+Resize.h
-// Created by Trevor Harmon on 8/5/09.
-// Free for personal or commercial use, with or without modification.
-// No warranty is expressed or implied.
-
-#import <UIKit/UIKit.h>
-
-
-// Extends the UIImage class to support resizing/cropping
-@interface UIImage (Resize)
-
-- (UIImage *)croppedImage: (CGRect)bounds;
-
-- (UIImage *)thumbnailImage: (NSInteger)thumbnailSize
- transparentBorder: (NSUInteger)borderSize
- cornerRadius: (NSUInteger)cornerRadius
- interpolationQuality: (CGInterpolationQuality)quality;
-
-- (UIImage *)resizedImage: (CGSize)newSize
- interpolationQuality: (CGInterpolationQuality)quality;
-
-- (UIImage *)resizedImageWithContentMode: (UIViewContentMode)contentMode
- bounds: (CGSize)bounds
- interpolationQuality: (CGInterpolationQuality)quality;
-@end
View
188 UIKitAdditions/UIImage+Resize.m
@@ -1,188 +0,0 @@
-// UIImage+Resize.m
-// Created by Trevor Harmon on 8/5/09.
-// Free for personal or commercial use, with or without modification.
-// No warranty is expressed or implied.
-
-#import "UIImage+Resize.h"
-#import "UIImage+RoundedCorner.h"
-#import "UIImage+Additions.h"
-
-// Private helper methods
-@interface UIImage ()
-- (UIImage *)resizedImage:(CGSize)newSize
- transform:(CGAffineTransform)transform
- drawTransposed:(BOOL)transpose
- interpolationQuality:(CGInterpolationQuality)quality;
-- (CGAffineTransform)transformForOrientation:(CGSize)newSize;
-@end
-
-@implementation UIImage (Resize)
-
-// Returns a copy of this image that is cropped to the given bounds.
-// The bounds will be adjusted using CGRectIntegral.
-// This method ignores the image's imageOrientation setting.
-- (UIImage *)croppedImage:(CGRect)bounds {
- CGImageRef imageRef = CGImageCreateWithImageInRect([self CGImage], bounds);
- UIImage *croppedImage = [UIImage imageWithCGImage:imageRef];
- CGImageRelease(imageRef);
- return croppedImage;
-}
-
-// Returns a copy of this image that is squared to the thumbnail size.
-// If transparentBorder is non-zero, a transparent border of the given size will be added around the edges of the thumbnail. (Adding a transparent border of at least one pixel in size has the side-effect of antialiasing the edges of the image when rotating it using Core Animation.)
-- (UIImage *)thumbnailImage:(NSInteger)thumbnailSize
- transparentBorder:(NSUInteger)borderSize
- cornerRadius:(NSUInteger)cornerRadius
- interpolationQuality:(CGInterpolationQuality)quality {
- UIImage *resizedImage = [self resizedImageWithContentMode:UIViewContentModeScaleAspectFill
- bounds:CGSizeMake(thumbnailSize, thumbnailSize)
- interpolationQuality:quality];
-
- // Crop out any part of the image that's larger than the thumbnail size
- // The cropped rect must be centered on the resized image
- // Round the origin points so that the size isn't altered when CGRectIntegral is later invoked
- CGRect cropRect = CGRectMake(round((resizedImage.size.width - thumbnailSize) / 2),
- round((resizedImage.size.height - thumbnailSize) / 2),
- thumbnailSize,
- thumbnailSize);
- UIImage *croppedImage = [resizedImage croppedImage:cropRect];
-
- UIImage *transparentBorderImage = borderSize ? [croppedImage transparentBorderImage:borderSize] : croppedImage;
-
- return [transparentBorderImage roundedCornerImage:cornerRadius borderSize:borderSize];
-}
-
-// Returns a rescaled copy of the image, taking into account its orientation
-// The image will be scaled disproportionately if necessary to fit the bounds specified by the parameter
-- (UIImage *)resizedImage:(CGSize)newSize interpolationQuality:(CGInterpolationQuality)quality {
- BOOL drawTransposed;
-
- switch (self.imageOrientation) {
- case UIImageOrientationLeft:
- case UIImageOrientationLeftMirrored:
- case UIImageOrientationRight:
- case UIImageOrientationRightMirrored:
- drawTransposed = YES;
- break;
-
- default:
- drawTransposed = NO;
- }
-
- return [self resizedImage:newSize
- transform:[self transformForOrientation:newSize]
- drawTransposed:drawTransposed
- interpolationQuality:quality];
-}
-
-// Resizes the image according to the given content mode, taking into account the image's orientation
-- (UIImage *)resizedImageWithContentMode:(UIViewContentMode)contentMode
- bounds:(CGSize)bounds
- interpolationQuality:(CGInterpolationQuality)quality {
- CGFloat horizontalRatio = bounds.width / self.size.width;
- CGFloat verticalRatio = bounds.height / self.size.height;
- CGFloat ratio;
-
- switch (contentMode) {
- case UIViewContentModeScaleAspectFill:
- ratio = MAX(horizontalRatio, verticalRatio);
- break;
-
- case UIViewContentModeScaleAspectFit:
- ratio = MIN(horizontalRatio, verticalRatio);
- break;
-
- default:
- [NSException raise:NSInvalidArgumentException format:@"Unsupported content mode: %d", contentMode];
- }
-
- CGSize newSize = CGSizeMake(self.size.width * ratio, self.size.height * ratio);
-
- return [self resizedImage:newSize interpolationQuality:quality];
-}
-
-#pragma mark -
-#pragma mark Private helper methods
-
-// Returns a copy of the image that has been transformed using the given affine transform and scaled to the new size
-// The new image's orientation will be UIImageOrientationUp, regardless of the current image's orientation
-// If the new size is not integral, it will be rounded up
-- (UIImage *)resizedImage:(CGSize)newSize
- transform:(CGAffineTransform)transform
- drawTransposed:(BOOL)transpose
- interpolationQuality:(CGInterpolationQuality)quality {
- CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height));
- CGRect transposedRect = CGRectMake(0, 0, newRect.size.height, newRect.size.width);
- CGImageRef imageRef = self.CGImage;
-
- // Build a context that's the same dimensions as the new size
- CGContextRef bitmap = CGBitmapContextCreate(NULL,
- newRect.size.width,
- newRect.size.height,
- CGImageGetBitsPerComponent(imageRef),
- 0,
- CGImageGetColorSpace(imageRef),
- CGImageGetBitmapInfo(imageRef));
-
- // Rotate and/or flip the image if required by its orientation
- CGContextConcatCTM(bitmap, transform);
-
- // Set the quality level to use when rescaling
- CGContextSetInterpolationQuality(bitmap, quality);
-
- // Draw into the context; this scales the image
- CGContextDrawImage(bitmap, transpose ? transposedRect : newRect, imageRef);
-
- // Get the resized image from the context and a UIImage
- CGImageRef newImageRef = CGBitmapContextCreateImage(bitmap);
- UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
-
- // Clean up
- CGContextRelease(bitmap);
- CGImageRelease(newImageRef);
-
- return newImage;
-}
-
-// Returns an affine transform that takes into account the image orientation when drawing a scaled image
-- (CGAffineTransform)transformForOrientation:(CGSize)newSize {
- CGAffineTransform transform = CGAffineTransformIdentity;
-
- switch (self.imageOrientation) {
- case UIImageOrientationDown: // EXIF = 3
- case UIImageOrientationDownMirrored: // EXIF = 4
- transform = CGAffineTransformTranslate(transform, newSize.width, newSize.height);
- transform = CGAffineTransformRotate(transform, M_PI);
- break;
-
- case UIImageOrientationLeft: // EXIF = 6
- case UIImageOrientationLeftMirrored: // EXIF = 5
- transform = CGAffineTransformTranslate(transform, newSize.width, 0);
- transform = CGAffineTransformRotate(transform, M_PI_2);
- break;
-
- case UIImageOrientationRight: // EXIF = 8
- case UIImageOrientationRightMirrored: // EXIF = 7
- transform = CGAffineTransformTranslate(transform, 0, newSize.height);
- transform = CGAffineTransformRotate(transform, -M_PI_2);
- break;
- }
-
- switch (self.imageOrientation) {
- case UIImageOrientationUpMirrored: // EXIF = 2
- case UIImageOrientationDownMirrored: // EXIF = 4
- transform = CGAffineTransformTranslate(transform, newSize.width, 0);
- transform = CGAffineTransformScale(transform, -1, 1);
- break;
-
- case UIImageOrientationLeftMirrored: // EXIF = 5
- case UIImageOrientationRightMirrored: // EXIF = 7
- transform = CGAffineTransformTranslate(transform, newSize.height, 0);
- transform = CGAffineTransformScale(transform, -1, 1);
- break;
- }
-
- return transform;
-}
-
-@end
View
15 UIKitAdditions/UIImage+RoundedCorner.h
@@ -1,15 +0,0 @@
-// UIImage+RoundedCorner.h
-// Created by Trevor Harmon on 9/20/09.
-// Free for personal or commercial use, with or without modification.
-// No warranty is expressed or implied.
-
-#import <UIKit/UIKit.h>
-
-
-// Extends the UIImage class to support making rounded corners
-@interface UIImage (RoundedCorner)
-
-- (UIImage *)roundedCornerImage: (NSInteger)cornerSize
- borderSize: (NSInteger)borderSize;
-
-@end
View
46 UIKitAdditions/UIImage+RoundedCorner.m
@@ -1,46 +0,0 @@
-// UIImage+RoundedCorner.m
-// Created by Trevor Harmon on 9/20/09.
-// Free for personal or commercial use, with or without modification.
-// No warranty is expressed or implied.
-
-#import "UIImage+RoundedCorner.h"
-#import "UIImage+Additions.h"
-#import "UIKit+DrawingHelpers.h"
-
-
-@implementation UIImage (RoundedCorner)
-
-// Creates a copy of this image with rounded corners
-// If borderSize is non-zero, a transparent border of the given size will also be added
-// Original author: Björn Sållarp. Used with permission. See: http://blog.sallarp.com/iphone-uiimage-round-corners/
-- (UIImage *)roundedCornerImage:(NSInteger)cornerSize borderSize:(NSInteger)borderSize {
- // If the image does not have an alpha layer, add one
- UIImage *image = [self imageWithAlpha];
-
- // Build a context that's the same dimensions as the new size
- CGContextRef context = CGBitmapContextCreate(NULL,
- image.size.width,
- image.size.height,
- CGImageGetBitsPerComponent(image.CGImage),
- 0,
- CGImageGetColorSpace(image.CGImage),
- CGImageGetBitmapInfo(image.CGImage));
-
- // Create a clipping path with rounded corners
- CGContextClipToRoundedRect(context, CGRectMake(borderSize, borderSize, image.size.width, image.size.height), cornerSize);
-
- // Draw the image to the context; the clipping path will make anything outside the rounded rect transparent
- CGContextDrawImage(context, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage);
-
- // Create a CGImage from the context
- CGImageRef clippedImage = CGBitmapContextCreateImage(context);
- CGContextRelease(context);
-
- // Create a UIImage from the CGImage
- UIImage *roundedImage = [UIImage imageWithCGImage:clippedImage];
- CGImageRelease(clippedImage);
-
- return roundedImage;
-}
-
-@end
View
17 UIKitAdditions/UITabBarController+HideableTabBar.h
@@ -1,17 +0,0 @@
-//
-// UITabBar+HidableTabBar.h
-// TBHidingTest
-//
-// Created by Marcel Ruegenberg on 11.06.11.
-// Copyright 2011 Dustlab. All rights reserved.
-//
-//
-
-// WARNING: The implementation of this category makes certain assumptions about the structure of the subviews of a UITabBarController's view. There is no guarantee for this to keep working from one version of iOS to the next.
-@interface UITabBarController (HideableTabBar)
-
-- (void)setTabBarHidden:(BOOL)hidden;
-
-- (void)setTabBarFlat:(BOOL)flat;
-
-@end
View
19 UIKitAdditions/UIView+Sliding.h
@@ -1,19 +0,0 @@
-//
-// UIView+Sliding.h
-// Classes
-//
-// Created by Marcel Ruegenberg on 13.09.11.
-// Copyright 2011 Dustlab. All rights reserved.
-//
-
-@interface UIView (UIView_Sliding)
-
-/**
- Slide in the view, as a direct child of the window.
- @param viewToAdjust A view whose size should be adjusted to make space for the new view.
- */
-- (void)slideInToView:(UIView *)parentView andAdjustView:(UIView *)viewToAdjust;