Browse files

Merge branch 'master' of github.com:samsoffes/sstoolkit

  • Loading branch information...
2 parents b36fa46 + 5b6fc0b commit 5f403d5f28830df0c0c7846d62c21e3c3930cac7 @soffes soffes committed Sep 16, 2011
View
16 SSToolkit.xcodeproj/project.pbxproj
@@ -10,8 +10,8 @@
AACBBE4A0F95108600F1A2B1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; };
B20AC0691267988600687143 /* SSTableViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = B20AC0671267988600687143 /* SSTableViewController.h */; };
B20AC06A1267988600687143 /* SSTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B20AC0681267988600687143 /* SSTableViewController.m */; };
- B2136B3C13ABCC0C00FEBCFD /* SSBordererView.h in Headers */ = {isa = PBXBuildFile; fileRef = B2136B3A13ABCC0C00FEBCFD /* SSBordererView.h */; };
- B2136B3D13ABCC0C00FEBCFD /* SSBordererView.m in Sources */ = {isa = PBXBuildFile; fileRef = B2136B3B13ABCC0C00FEBCFD /* SSBordererView.m */; };
+ B2136B3C13ABCC0C00FEBCFD /* SSBorderedView.h in Headers */ = {isa = PBXBuildFile; fileRef = B2136B3A13ABCC0C00FEBCFD /* SSBorderedView.h */; };
+ B2136B3D13ABCC0C00FEBCFD /* SSBorderedView.m in Sources */ = {isa = PBXBuildFile; fileRef = B2136B3B13ABCC0C00FEBCFD /* SSBorderedView.m */; };
B215045F10583A7300409ED4 /* SSToolkit_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = B215045E10583A7300409ED4 /* SSToolkit_Prefix.pch */; };
B215051210583BBB00409ED4 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B215051110583BBB00409ED4 /* UIKit.framework */; };
B21D2E00121F2FE500161E66 /* SSDrawingUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = B21D2DFF121F2FE500161E66 /* SSDrawingUtilities.m */; };
@@ -147,8 +147,8 @@
AACBBE490F95108600F1A2B1 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
B20AC0671267988600687143 /* SSTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSTableViewController.h; sourceTree = "<group>"; };
B20AC0681267988600687143 /* SSTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSTableViewController.m; sourceTree = "<group>"; };
- B2136B3A13ABCC0C00FEBCFD /* SSBordererView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSBordererView.h; sourceTree = "<group>"; };
- B2136B3B13ABCC0C00FEBCFD /* SSBordererView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSBordererView.m; sourceTree = "<group>"; };
+ B2136B3A13ABCC0C00FEBCFD /* SSBorderedView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSBorderedView.h; sourceTree = "<group>"; };
+ B2136B3B13ABCC0C00FEBCFD /* SSBorderedView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSBorderedView.m; sourceTree = "<group>"; };
B215045E10583A7300409ED4 /* SSToolkit_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSToolkit_Prefix.pch; sourceTree = "<group>"; };
B215051110583BBB00409ED4 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
B21D2DFF121F2FE500161E66 /* SSDrawingUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSDrawingUtilities.m; sourceTree = "<group>"; };
@@ -458,8 +458,8 @@
B290355913B9236E00CCAFC9 /* SSAnimatedImageView.m */,
B2EA9F6012F4A5E100C929D6 /* SSBadgeView.h */,
B2EA9F6112F4A5E100C929D6 /* SSBadgeView.m */,
- B2136B3A13ABCC0C00FEBCFD /* SSBordererView.h */,
- B2136B3B13ABCC0C00FEBCFD /* SSBordererView.m */,
+ B2136B3A13ABCC0C00FEBCFD /* SSBorderedView.h */,
+ B2136B3B13ABCC0C00FEBCFD /* SSBorderedView.m */,
B27B1A1912241D3400111EA2 /* SSCollectionView.h */,
B27B1A1A12241D3400111EA2 /* SSCollectionView.m */,
B27B1A2012241D6F00111EA2 /* SSCollectionViewItem.h */,
@@ -627,7 +627,7 @@
B2FC71BB1330424F00D4FCCF /* SSCollectionViewItemInternal.h in Headers */,
B2D8829413328EEF006B3F55 /* SSHUDWindow.h in Headers */,
B25C8E611394327000DE7BFF /* SSCollectionViewExtremityTableViewCell.h in Headers */,
- B2136B3C13ABCC0C00FEBCFD /* SSBordererView.h in Headers */,
+ B2136B3C13ABCC0C00FEBCFD /* SSBorderedView.h in Headers */,
B280E25F13BA76A300FCDA5C /* SSAnimatedImageView.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -779,7 +779,7 @@
B2ABC6931329D14300521D20 /* SSCollectionViewItemTableViewCell.m in Sources */,
B2D8829513328EEF006B3F55 /* SSHUDWindow.m in Sources */,
B25C8E601394327000DE7BFF /* SSCollectionViewExtremityTableViewCell.m in Sources */,
- B2136B3D13ABCC0C00FEBCFD /* SSBordererView.m in Sources */,
+ B2136B3D13ABCC0C00FEBCFD /* SSBorderedView.m in Sources */,
B280E25D13BA769C00FCDA5C /* SSAnimatedImageView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
View
24 SSToolkit/NSArray+SSToolkitAdditions.h
@@ -40,4 +40,28 @@
*/
- (NSArray *)shuffledArray;
+///--------------
+/// @name Hashing
+///--------------
+
+/**
+ Returns a string of the MD5 sum of the receiver.
+
+ @return The string of the MD5 sum of the receiver.
+
+ Internally, `NSPropertyListSerialization` is used to created the hash. Only objects that can be serialized should be
+ contained in the receiver when calling this method.
+ */
+- (NSString *)MD5Sum;
+
+/**
+ Returns a string of the SHA1 sum of the receiver.
+
+ @return The string of the SHA1 sum of the receiver.
+
+ Internally, `NSPropertyListSerialization` is used to created the hash. Only objects that can be serialized should be
+ contained in the receiver when calling this method.
+ */
+- (NSString *)SHA1Sum;
+
@end
View
24 SSToolkit/NSArray+SSToolkitAdditions.m
@@ -7,6 +7,11 @@
//
#import "NSArray+SSToolkitAdditions.h"
+#import "NSData+SSToolkitAdditions.h"
+
+@interface NSArray (SSToolkitPrivateAdditions)
+- (NSData *)_prehashData;
+@end
@implementation NSArray (SSToolkitAdditions)
@@ -36,4 +41,23 @@ - (NSArray *)shuffledArray {
return array;
}
+
+- (NSString *)MD5Sum {
+ return [[self _prehashData] MD5Sum];
+}
+
+
+- (NSString *)SHA1Sum {
+ return [[self _prehashData] SHA1Sum];
+}
+
+@end
+
+
+@implementation NSArray (SSToolkitPrivateAdditions)
+
+- (NSData *)_prehashData {
+ return [NSPropertyListSerialization dataWithPropertyList:self format:NSPropertyListBinaryFormat_v1_0 options:0 error:nil];
+}
+
@end
View
24 SSToolkit/NSDictionary+SSToolkitAdditions.h
@@ -36,4 +36,28 @@
*/
- (NSString *)stringWithFormEncodedComponents;
+///--------------
+/// @name Hashing
+///--------------
+
+/**
+ Returns a string of the MD5 sum of the receiver.
+
+ @return The string of the MD5 sum of the receiver.
+
+ Internally, `NSPropertyListSerialization` is used to created the hash. Only objects that can be serialized should be
+ contained in the receiver when calling this method.
+ */
+- (NSString *)MD5Sum;
+
+/**
+ Returns a string of the SHA1 sum of the receiver.
+
+ @return The string of the SHA1 sum of the receiver.
+
+ Internally, `NSPropertyListSerialization` is used to created the hash. Only objects that can be serialized should be
+ contained in the receiver when calling this method.
+ */
+- (NSString *)SHA1Sum;
+
@end
View
24 SSToolkit/NSDictionary+SSToolkitAdditions.m
@@ -8,6 +8,11 @@
#import "NSDictionary+SSToolkitAdditions.h"
#import "NSString+SSToolkitAdditions.h"
+#import "NSData+SSToolkitAdditions.h"
+
+@interface NSDictionary (SSToolkitPrivateAdditions)
+- (NSData *)_prehashData;
+@end
@implementation NSDictionary (SSToolkitAdditions)
@@ -57,4 +62,23 @@ - (NSString *)stringWithFormEncodedComponents {
return [arguments componentsJoinedByString:@"&"];
}
+
+- (NSString *)MD5Sum {
+ return [[self _prehashData] MD5Sum];
+}
+
+
+- (NSString *)SHA1Sum {
+ return [[self _prehashData] SHA1Sum];
+}
+
+@end
+
+
+@implementation NSDictionary (SSToolkitPrivateAdditions)
+
+- (NSData *)_prehashData {
+ return [NSPropertyListSerialization dataWithPropertyList:self format:NSPropertyListBinaryFormat_v1_0 options:0 error:nil];
+}
+
@end
View
12 SSToolkit/SSBadgeView.m
@@ -19,8 +19,9 @@ @implementation SSBadgeView
@synthesize badgeColor = _badgeColor;
- (void)setBadgeColor:(UIColor *)badgeColor {
+ [badgeColor retain];
[_badgeColor release];
- _badgeColor = [badgeColor retain];
+ _badgeColor = badgeColor;
[self setNeedsDisplay];
}
@@ -29,26 +30,29 @@ - (void)setBadgeColor:(UIColor *)badgeColor {
@synthesize highlightedBadgeColor = _highlightedBadgeColor;
- (void)setHighlightedBadgeColor:(UIColor *)highlightedBadgeColor {
+ [highlightedBadgeColor retain];
[_highlightedBadgeColor release];
- _highlightedBadgeColor = [highlightedBadgeColor retain];
+ _highlightedBadgeColor = highlightedBadgeColor;
[self setNeedsDisplay];
}
@synthesize badgeImage = _badgeImage;
- (void)setBadgeImage:(UIImage *)badgeImage {
+ [badgeImage retain];
[_badgeImage release];
- _badgeImage = [badgeImage retain];
+ _badgeImage = badgeImage;
[self setNeedsDisplay];
}
@synthesize highlightedBadgeImage = _highlightedBadgeImage;
- (void)setHighlightedBadgeImage:(UIImage *)highlightedBadgeImage {
+ [highlightedBadgeImage retain];
[_highlightedBadgeImage release];
- _highlightedBadgeImage = [highlightedBadgeImage retain];
+ _highlightedBadgeImage = highlightedBadgeImage;
[self setNeedsDisplay];
}
View
4 SSToolkit/SSBordererView.h → SSToolkit/SSBorderedView.h
@@ -1,5 +1,5 @@
//
-// SSBordererView.h
+// SSBorderedView.h
// SSToolkit
//
// Created by Sam Soffes on 6/17/11.
@@ -9,7 +9,7 @@
/**
Simple UIView for drawing top and bottom borders with optional insets in a view.
*/
-@interface SSBordererView : UIView {
+@interface SSBorderedView : UIView {
@private
View
18 SSToolkit/SSBordererView.m → SSToolkit/SSBorderedView.m
@@ -1,23 +1,24 @@
//
-// SSBordererView.m
+// SSBorderedView.m
// SSToolkit
//
// Created by Sam Soffes on 6/17/11.
// Copyright 2011 Sam Soffes. All rights reserved.
//
-#import "SSBordererView.h"
+#import "SSBorderedView.h"
#import "SSDrawingUtilities.h"
-@implementation SSBordererView
+@implementation SSBorderedView
#pragma mark - Accessors
@synthesize topBorderColor = _topBorderColor;
- (void)setTopBorderColor:(UIColor *)topBorderColor {
+ [topBorderColor retain];
[_topBorderColor release];
- _topBorderColor = [topBorderColor retain];
+ _topBorderColor = topBorderColor;
[self setNeedsDisplay];
}
@@ -26,8 +27,9 @@ - (void)setTopBorderColor:(UIColor *)topBorderColor {
@synthesize topInsetColor = _topInsetColor;
- (void)setTopInsetColor:(UIColor *)topInsetColor {
+ [topInsetColor retain];
[_topInsetColor release];
- _topInsetColor = [topInsetColor retain];
+ _topInsetColor = topInsetColor;
[self setNeedsDisplay];
}
@@ -36,8 +38,9 @@ - (void)setTopInsetColor:(UIColor *)topInsetColor {
@synthesize bottomInsetColor = _bottomInsetColor;
- (void)setBottomInsetColor:(UIColor *)bottomInsetColor {
+ [bottomInsetColor retain];
[_bottomInsetColor release];
- _bottomInsetColor = [bottomInsetColor retain];
+ _bottomInsetColor = bottomInsetColor;
[self setNeedsDisplay];
}
@@ -46,8 +49,9 @@ - (void)setBottomInsetColor:(UIColor *)bottomInsetColor {
@synthesize bottomBorderColor = _bottomBorderColor;
- (void)setBottomBorderColor:(UIColor *)bottomBorderColor {
+ [bottomBorderColor retain];
[_bottomBorderColor release];
- _bottomBorderColor = [bottomBorderColor retain];
+ _bottomBorderColor = bottomBorderColor;
[self setNeedsDisplay];
}
View
14 SSToolkit/SSCollectionView.h
@@ -113,6 +113,20 @@ typedef enum {
@property (nonatomic, retain) UIView *backgroundView;
/**
+ Returns an accessory view that is displayed above the collection.
+
+ The default value is `nil`. The collection header view is different from a section header.
+ */
+@property (nonatomic, retain) UIView *collectionHeaderView;
+
+/**
+ Returns an accessory view that is displayed below the collection.
+
+ The default value is `nil`. The collection footer view is different from a section footer.
+ */
+@property (nonatomic, retain) UIView *collectionFooterView;
+
+/**
A Boolean value that determines whether selecting items is enabled.
If the value of this property is `YES`, selecting is enabled, and if it is `NO`, selecting is disabled. The default is
View
34 SSToolkit/SSCollectionView.m
@@ -88,14 +88,34 @@ - (UIView *)backgroundView {
}
-- (void)setBackgroundColor:(UIColor *)color {
- [super setBackgroundColor:color];
- _tableView.backgroundColor = color;
+- (void)setBackgroundView:(UIView *)background {
+ _tableView.backgroundView = background;
}
-- (void)setBackgroundView:(UIView *)background {
- _tableView.backgroundView = background;
+- (UIView *)collectionHeaderView {
+ return _tableView.tableHeaderView;
+}
+
+
+- (void)setCollectionHeaderView:(UIView *)collectionHeaderView {
+ _tableView.tableHeaderView = collectionHeaderView;
+}
+
+
+- (UIView *)collectionFooterView {
+ return _tableView.tableFooterView;
+}
+
+
+- (void)setCollectionFooterView:(UIView *)collectionFooterView {
+ _tableView.tableFooterView = collectionFooterView;
+}
+
+
+- (void)setBackgroundColor:(UIColor *)color {
+ [super setBackgroundColor:color];
+ _tableView.backgroundColor = color;
}
@@ -425,7 +445,7 @@ - (NSArray *)_itemsForRowIndexPath:(NSIndexPath *)rowIndexPath {
NSUInteger startIndex = itemsPerRow * row;
NSUInteger endIndex = (NSUInteger)fmin(totalItems, startIndex + itemsPerRow);
- NSMutableArray *items = [[NSMutableArray alloc] initWithCapacity:endIndex - startIndex];
+ NSMutableArray *items = [[[NSMutableArray alloc] initWithCapacity:endIndex - startIndex] autorelease];
for (NSUInteger i = startIndex; i < endIndex; i++) {
NSIndexPath *itemIndexPath = [NSIndexPath indexPathForRow:i inSection:rowIndexPath.section];
@@ -444,7 +464,7 @@ - (NSArray *)_itemsForRowIndexPath:(NSIndexPath *)rowIndexPath {
[items addObject:item];
}
- return [items autorelease];
+ return items;
}
View
3 SSToolkit/SSCollectionViewExtremityTableViewCell.m
@@ -15,9 +15,10 @@ @implementation SSCollectionViewExtremityTableViewCell
@synthesize extrimityView = _extrimityView;
- (void)setExtrimityView:(UIView *)view {
+ [view retain];
[_extrimityView removeFromSuperview];
[_extrimityView release];
- _extrimityView = [view retain];
+ _extrimityView = view;
[self addSubview:_extrimityView];
}
View
4 SSToolkit/SSGradientView.h
@@ -6,7 +6,7 @@
// Copyright 2009-2011 Sam Soffes. All rights reserved.
//
-#import "SSBordererView.h"
+#import "SSBorderedView.h"
/**
The direction the gradient.
@@ -22,7 +22,7 @@ typedef enum {
/**
Simple `UIView` wrapper for `CGGradient`.
*/
-@interface SSGradientView : SSBordererView {
+@interface SSGradientView : SSBorderedView {
@private
View
6 SSToolkit/SSGradientView.m
@@ -21,17 +21,19 @@ @implementation SSGradientView
@synthesize colors = _colors;
- (void)setColors:(NSArray *)colors {
+ [colors retain];
[_colors release];
- _colors = [colors retain];
+ _colors = colors;
[self _refreshGradient];
}
@synthesize locations = _locations;
- (void)setLocations:(NSArray *)locations {
+ [locations retain];
[_locations release];
- _locations = [locations retain];
+ _locations = locations;
[self _refreshGradient];
}
View
8 SSToolkit/SSLineView.m
@@ -13,8 +13,9 @@ @implementation SSLineView
@synthesize lineColor = _lineColor;
- (void)setLineColor:(UIColor *)lineColor {
+ [lineColor retain];
[_lineColor release];
- _lineColor = [lineColor retain];
+ _lineColor = lineColor;
[self setNeedsDisplay];
}
@@ -23,8 +24,9 @@ - (void)setLineColor:(UIColor *)lineColor {
@synthesize insetColor = _insetColor;
- (void)setInsetColor:(UIColor *)insetColor {
+ [insetColor retain];
[_insetColor release];
- _insetColor = [insetColor retain];
+ _insetColor = insetColor;
[self setNeedsDisplay];
}
@@ -42,7 +44,7 @@ - (void)setDashPhase:(CGFloat)dashPhase {
@synthesize dashLengths = _dashLengths;
- (void)setDashLengths:(NSArray *)dashLengths {
- [_dashLengths release];
+ [_dashLengths autorelease];
_dashLengths = [dashLengths copy];
[self setNeedsDisplay];
View
9 SSToolkit/SSPieProgressView.m
@@ -35,8 +35,9 @@ - (void)setPieBorderWidth:(CGFloat)pieBorderWidth {
@synthesize pieBorderColor = _pieBorderColor;
- (void)setPieBorderColor:(UIColor *)pieBorderColor {
+ [pieBorderColor retain];
[_pieBorderColor release];
- _pieBorderColor = [pieBorderColor retain];
+ _pieBorderColor = pieBorderColor;
[self setNeedsDisplay];
}
@@ -45,8 +46,9 @@ - (void)setPieBorderColor:(UIColor *)pieBorderColor {
@synthesize pieFillColor = _pieFillColor;
- (void)setPieFillColor:(UIColor *)pieFillColor {
+ [pieFillColor retain];
[_pieFillColor release];
- _pieFillColor = [pieFillColor retain];
+ _pieFillColor = pieFillColor;
[self setNeedsDisplay];
}
@@ -55,8 +57,9 @@ - (void)setPieFillColor:(UIColor *)pieFillColor {
@synthesize pieBackgroundColor = _pieBackgroundColor;
- (void)setPieBackgroundColor:(UIColor *)pieBackgroundColor {
+ [pieBackgroundColor retain];
[_pieBackgroundColor release];
- _pieBackgroundColor = [pieBackgroundColor retain];
+ _pieBackgroundColor = pieBackgroundColor;
[self setNeedsDisplay];
}
View
24 SSToolkit/SSSegmentedControl.m
@@ -30,8 +30,9 @@ - (NSUInteger)numberOfSegments {
@synthesize buttonImage = _buttonImage;
- (void)setButtonImage:(UIImage *)buttonImage {
+ [buttonImage retain];
[_buttonImage release];
- _buttonImage = [buttonImage retain];
+ _buttonImage = buttonImage;
[self setNeedsDisplay];
}
@@ -40,8 +41,9 @@ - (void)setButtonImage:(UIImage *)buttonImage {
@synthesize highlightedButtonImage = _highlightedButtonImage;
- (void)setHighlightedButtonImage:(UIImage *)highlightedButtonImage {
+ [highlightedButtonImage retain];
[_highlightedButtonImage release];
- _highlightedButtonImage = [highlightedButtonImage retain];
+ _highlightedButtonImage = highlightedButtonImage;
[self setNeedsDisplay];
}
@@ -50,8 +52,9 @@ - (void)setHighlightedButtonImage:(UIImage *)highlightedButtonImage {
@synthesize dividerImage = _dividerImage;
- (void)setDividerImage:(UIImage *)dividerImage {
+ [dividerImage retain];
[_dividerImage release];
- _dividerImage = [dividerImage retain];
+ _dividerImage = dividerImage;
[self setNeedsDisplay];
}
@@ -60,8 +63,9 @@ - (void)setDividerImage:(UIImage *)dividerImage {
@synthesize highlightedDividerImage = _highlightedDividerImage;
- (void)setHighlightedDividerImage:(UIImage *)highlightedDividerImage {
+ [highlightedDividerImage retain];
[_highlightedDividerImage release];
- _highlightedDividerImage = [highlightedDividerImage retain];
+ _highlightedDividerImage = highlightedDividerImage;
[self setNeedsDisplay];
}
@@ -70,8 +74,9 @@ - (void)setHighlightedDividerImage:(UIImage *)highlightedDividerImage {
@synthesize font = _font;
- (void)setFont:(UIFont *)font {
+ [font retain];
[_font release];
- _font = [font retain];
+ _font = font;
[self setNeedsDisplay];
}
@@ -80,17 +85,19 @@ - (void)setFont:(UIFont *)font {
@synthesize textColor = _textColor;
- (void)setTextColor:(UIColor *)textColor {
+ [textColor retain];
[_textColor release];
- _textColor = [textColor retain];
+ _textColor = textColor;
[self setNeedsDisplay];
}
@synthesize disabledTextColor = _disabledTextColor;
- (void)setDisabledTextColor:(UIColor *)disabledTextColor {
+ [disabledTextColor retain];
[_disabledTextColor release];
- _disabledTextColor = [disabledTextColor retain];
+ _disabledTextColor = disabledTextColor;
[self setNeedsDisplay];
}
@@ -99,8 +106,9 @@ - (void)setDisabledTextColor:(UIColor *)disabledTextColor {
@synthesize textShadowColor = _textShadowColor;
- (void)setTextShadowColor:(UIColor *)textShadowColor {
+ [textShadowColor retain];
[_textShadowColor release];
- _textShadowColor = [textShadowColor retain];
+ _textShadowColor = textShadowColor;
[self setNeedsDisplay];
}
View
18 SSToolkit/SSSwitch.m
@@ -81,8 +81,9 @@ - (void)setStyle:(SSSwitchStyle)s {
@synthesize leftHandleImage = _leftHandleImage;
- (void)setLeftHandleImage:(UIImage *)leftHandleImage {
+ [leftHandleImage retain];
[_leftHandleImage release];
- _leftHandleImage = [leftHandleImage retain];
+ _leftHandleImage = leftHandleImage;
[self setNeedsDisplay];
}
@@ -91,8 +92,9 @@ - (void)setLeftHandleImage:(UIImage *)leftHandleImage {
@synthesize leftHandleImageHighlighted = _leftHandleImageHighlighted;
- (void)setLeftHandleImageHighlighted:(UIImage *)leftHandleImageHighlighted {
+ [leftHandleImageHighlighted retain];
[_leftHandleImageHighlighted release];
- _leftHandleImageHighlighted = [leftHandleImageHighlighted retain];
+ _leftHandleImageHighlighted = leftHandleImageHighlighted;
[self setNeedsDisplay];
}
@@ -101,8 +103,9 @@ - (void)setLeftHandleImageHighlighted:(UIImage *)leftHandleImageHighlighted {
@synthesize centerHandleImage = _centerHandleImage;
- (void)setCenterHandleImage:(UIImage *)centerHandleImage {
+ [centerHandleImage retain];
[_centerHandleImage release];
- _centerHandleImage = [centerHandleImage retain];
+ _centerHandleImage = centerHandleImage;
[self setNeedsDisplay];
}
@@ -111,8 +114,9 @@ - (void)setCenterHandleImage:(UIImage *)centerHandleImage {
@synthesize centerHandleImageHighlighted = _centerHandleImageHighlighted;
- (void)setCenterHandleImageHighlighted:(UIImage *)centerHandleImageHighlighted {
+ [centerHandleImageHighlighted retain];
[_centerHandleImageHighlighted release];
- _centerHandleImageHighlighted = [centerHandleImageHighlighted retain];
+ _centerHandleImageHighlighted = centerHandleImageHighlighted;
[self setNeedsDisplay];
}
@@ -121,8 +125,9 @@ - (void)setCenterHandleImageHighlighted:(UIImage *)centerHandleImageHighlighted
@synthesize rightHandleImage = _rightHandleImage;
- (void)setRightHandleImage:(UIImage *)rightHandleImage {
+ [rightHandleImage retain];
[_rightHandleImage release];
- _rightHandleImage = [rightHandleImage retain];
+ _rightHandleImage = rightHandleImage;
[self setNeedsDisplay];
}
@@ -131,8 +136,9 @@ - (void)setRightHandleImage:(UIImage *)rightHandleImage {
@synthesize rightHandleImageHighlighted = _rightHandleImageHighlighted;
- (void)setRightHandleImageHighlighted:(UIImage *)rightHandleImageHighlighted {
+ [rightHandleImageHighlighted retain];
[_rightHandleImageHighlighted release];
- _rightHandleImageHighlighted = [rightHandleImageHighlighted retain];
+ _rightHandleImageHighlighted = rightHandleImageHighlighted;
[self setNeedsDisplay];
}
View
19 SSToolkit/SSTextField.h
@@ -15,8 +15,27 @@
UIEdgeInsets _textEdgeInsets;
UIEdgeInsets _clearButtonEdgeInsets;
+ UIColor *_placeholderTextColor;
}
+///------------------------------------
+/// @name Accessing the Text Attributes
+///------------------------------------
+
+/**
+ The color of the placeholder text.
+
+ This property applies to the entire placeholder text string. The default value for this property is set by the system.
+ Setting this property to `nil` will use the system placeholder text color.
+
+ The default value is `nil`.
+ */
+@property (nonatomic, retain) UIColor *placeholderTextColor;
+
+///------------------------------
+/// @name Drawing and Positioning
+///------------------------------
+
/**
The inset or outset margins for the edges of the text content drawing rectangle.
View
30 SSToolkit/SSTextField.m
@@ -15,6 +15,25 @@ @implementation SSTextField
@synthesize textEdgeInsets = _textEdgeInsets;
@synthesize clearButtonEdgeInsets = _clearButtonEdgeInsets;
+@synthesize placeholderTextColor = _placeholderTextColor;
+
+- (void)setPlaceholderTextColor:(UIColor *)placeholderTextColor {
+ [placeholderTextColor retain];
+ [_placeholderTextColor release];
+ _placeholderTextColor = placeholderTextColor;
+
+ if (!self.text && self.placeholder) {
+ [self setNeedsDisplay];
+ }
+}
+
+
+#pragma mark - NSObject
+
+- (void)dealloc {
+ [_placeholderTextColor release];
+ [super dealloc];
+}
#pragma mark - UIView
@@ -46,4 +65,15 @@ - (CGRect)clearButtonRectForBounds:(CGRect)bounds {
return CGRectSetX(rect, rect.origin.x + _clearButtonEdgeInsets.right);
}
+
+- (void)drawPlaceholderInRect:(CGRect)rect {
+ if (!_placeholderTextColor) {
+ [super drawPlaceholderInRect:rect];
+ return;
+ }
+
+ [_placeholderTextColor setFill];
+ [self.placeholder drawInRect:rect withFont:self.font lineBreakMode:UILineBreakModeTailTruncation alignment:self.textAlignment];
+}
+
@end
View
4 SSToolkit/SSToolkit.h
@@ -14,7 +14,7 @@
// Views
#import "SSAnimatedImageView.h"
#import "SSBadgeView.h"
-#import "SSBordererView.h"
+#import "SSBorderedView.h"
#import "SSCollectionView.h"
#import "SSCollectionViewItem.h"
#import "SSGradientView.h"
@@ -55,7 +55,7 @@
// Views
#import <SSToolkit/SSAnimatedImageView.h>
#import <SSToolkit/SSBadgeView.h>
-#import <SSToolkit/SSBordererView.h>
+#import <SSToolkit/SSBorderedView.h>
#import <SSToolkit/SSCollectionView.h>
#import <SSToolkit/SSCollectionViewItem.h>
#import <SSToolkit/SSGradientView.h>
View
47 SSToolkit/UIApplication+SSToolkitAdditions.h
@@ -11,13 +11,38 @@
*/
@interface UIApplication (SSToolkitAdditions)
-/** Checks for pirated application indicators.
-
- This isn't bulletproof, but should catch a lot of cases. Thanks @marcoarment: http://twitter.com/marcoarment/status/27965461020
-
- @return `YES` if the application may be pirated. `NO` if it is probably not pirated.
+///------------------
+/// @name Directories
+///------------------
+
+/**
+ Returns the file URL of the documents directory.
*/
-- (BOOL)isPirated;
+@property (nonatomic, retain, readonly) NSURL *documentsDirectoryURL;
+
+/**
+ Returns the file URL of the caches directory.
+ */
+@property (nonatomic, retain, readonly) NSURL *cachesDirectoryURL;
+
+/**
+ Returns the file URL of the downloads directory.
+ */
+@property (nonatomic, retain, readonly) NSURL *downloadsDirectoryURL;
+
+/**
+ Returns the file URL of the library directory.
+ */
+@property (nonatomic, retain, readonly) NSURL *libraryDirectoryURL;
+
+/**
+ Returns the file URL of the application support directory.
+ */
+@property (nonatomic, retain, readonly) NSURL *applicationSupportDirectoryURL;
+
+///----------------
+/// @name Utilities
+///----------------
/**
Aggregates calls to settings `networkActivityIndicatorVisible` to avoid flashing of the indicator in the status bar.
@@ -31,4 +56,14 @@
*/
- (void)setNetworkActivity:(BOOL)inProgress;
+/** Checks for pirated application indicators.
+
+ This isn't bulletproof, but should catch a lot of cases.
+
+ Thanks Marco Arment: <http://twitter.com/marcoarment/status/27965461020>
+
+ @return `YES` if the application may be pirated. `NO` if it is probably not pirated.
+ */
+- (BOOL)isPirated;
+
@end
View
24 SSToolkit/UIApplication+SSToolkitAdditions.m
@@ -33,6 +33,30 @@ - (void)setNetworkActivity:(BOOL)inProgress {
}
}
+
+- (NSURL *)documentsDirectoryURL {
+ return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
+}
+
+
+- (NSURL *)cachesDirectoryURL {
+ return [[[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask] lastObject];
+}
+
+- (NSURL *)downloadsDirectoryURL {
+ return [[[NSFileManager defaultManager] URLsForDirectory:NSDownloadsDirectory inDomains:NSUserDomainMask] lastObject];
+}
+
+
+- (NSURL *)libraryDirectoryURL {
+ return [[[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] lastObject];
+}
+
+
+- (NSURL *)applicationSupportDirectoryURL {
+ return [[[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask] lastObject];
+}
+
@end
View
44 SSToolkit/UIColor+SSToolkitAdditions.h
@@ -12,6 +12,50 @@
@interface UIColor (SSToolkitAdditions)
/**
+ Creates and returns an UIColor object containing a given value.
+
+ @param hex The value for the new color. The `#` sign is optional.
+
+ @return An UIColor object containing a value.
+
+ The alpha value will be `1.0`.
+ */
++ (UIColor *)colorWithHex:(NSString *)hex;
+
+/**
+ Returns the receiver's value as a hex string.
+
+ @return The receiver's value as a hex string.
+
+ The value will be `nil` if the color is in a color space other than Grayscale or RGB. The `#` sign is omitted.
+ */
+- (NSString *)hexValue;
+
+/**
+ The receiver's red component value. (read-only)
+
+ The value of this property is a floating-point number in the range `0.0` to `1.0`. `-1.0` is returned if the color is
+ not in the RGB colorspace.
+ */
+@property (nonatomic, assign, readonly) CGFloat red;
+
+/**
+ The receiver's green component value. (read-only)
+
+ The value of this property is a floating-point number in the range `0.0` to `1.0`. `-1.0` is returned if the color is
+ not in the RGB colorspace.
+ */
+@property (nonatomic, assign, readonly) CGFloat green;
+
+/**
+ The receiver's blue component value. (read-only)
+
+ The value of this property is a floating-point number in the range `0.0` to `1.0`. `-1.0` is returned if the color is
+ not in the RGB colorspace.
+ */
+@property (nonatomic, assign, readonly) CGFloat blue;
+
+/**
The receiver's alpha value. (read-only)
The value of this property is a floating-point number in the range `0.0` to `1.0`, where `0.0` represents totally
View
85 SSToolkit/UIColor+SSToolkitAdditions.m
@@ -8,8 +8,93 @@
#import "UIColor+SSToolkitAdditions.h"
+static NSUInteger integerFromHexString(NSString *string) {
+ NSUInteger result = 0;
+ sscanf([string UTF8String], "%x", &result);
+ return result;
+}
+
@implementation UIColor (SSToolkitAdditions)
+// Adapted from https://github.com/Cocoanetics/NSAttributedString-Additions-for-HTML
++ (UIColor *)colorWithHex:(NSString *)hex {
+ // Remove `#`
+ if ([[hex substringWithRange:NSMakeRange(0, 1)] isEqualToString:@"#"]) {
+ hex = [hex substringFromIndex:1];
+ }
+
+ // Invalid if not 3, or 6 characters
+ NSUInteger length = [hex length];
+ if (length != 3 && length != 6) {
+ return nil;
+ }
+
+ NSUInteger digits = length / 3;
+ CGFloat maxValue = (digits == 1) ? 15.0f : 255.0f;
+
+ CGFloat red = integerFromHexString([hex substringWithRange:NSMakeRange(0, digits)]) / maxValue;
+ CGFloat green = integerFromHexString([hex substringWithRange:NSMakeRange(digits, digits)]) / maxValue;
+ CGFloat blue = integerFromHexString([hex substringWithRange:NSMakeRange(2 * digits, digits)]) / maxValue;
+
+ return [UIColor colorWithRed:red green:green blue:blue alpha:1.0f];
+}
+
+
+// Inspired by https://github.com/Cocoanetics/NSAttributedString-Additions-for-HTML
+- (NSString *)hexValue {
+ CGColorRef color = self.CGColor;
+ size_t count = CGColorGetNumberOfComponents(color);
+ const CGFloat *components = CGColorGetComponents(color);
+
+ static NSString *stringFormat = @"%02x%02x%02x";
+
+ // Grayscale
+ if (count == 2) {
+ NSUInteger white = (NSUInteger)(components[0] * (CGFloat)255);
+ return [NSString stringWithFormat:stringFormat, white, white, white];
+ }
+
+ // RGB
+ else if (count == 4) {
+ return [NSString stringWithFormat:stringFormat, (NSUInteger)(components[0] * (CGFloat)255),
+ (NSUInteger)(components[1] * (CGFloat)255), (NSUInteger)(components[2] * (CGFloat)255)];
+ }
+
+ // Unsupported color space
+ return nil;
+}
+
+
+- (CGFloat)red {
+ CGColorRef color = self.CGColor;
+ if (CGColorSpaceGetModel(CGColorGetColorSpace(color)) != kCGColorSpaceModelRGB) {
+ return -1.0f;
+ }
+ CGFloat const *components = CGColorGetComponents(color);
+ return components[0];
+}
+
+
+- (CGFloat)green {
+ CGColorRef color = self.CGColor;
+ if (CGColorSpaceGetModel(CGColorGetColorSpace(color)) != kCGColorSpaceModelRGB) {
+ return -1.0f;
+ }
+ CGFloat const *components = CGColorGetComponents(color);
+ return components[1];
+}
+
+
+- (CGFloat)blue {
+ CGColorRef color = self.CGColor;
+ if (CGColorSpaceGetModel(CGColorGetColorSpace(color)) != kCGColorSpaceModelRGB) {
+ return -1.0f;
+ }
+ CGFloat const *components = CGColorGetComponents(color);
+ return components[2];
+}
+
+
- (CGFloat)alpha {
return CGColorGetAlpha(self.CGColor);
}
View
6 SSToolkit/UIImage+SSToolkitAdditions.m
@@ -23,11 +23,11 @@ + (UIImage *)imageNamed:(NSString *)imageName bundleName:(NSString *)bundleName
- (UIImage *)imageCroppedToRect:(CGRect)rect {
- // CGImageCreateWithImageInRect's rect parameter is in pixels of the image's coordinates system. Convert to points.
+ // CGImageCreateWithImageInRect's `rect` parameter is in pixels of the image's coordinates system. Convert from points.
CGFloat scale = self.scale;
- rect = CGRectMake(rect.origin.x *scale, rect.origin.y * scale, rect.size.width * scale, rect.size.height * scale);
+ rect = CGRectMake(rect.origin.x * scale, rect.origin.y * scale, rect.size.width * scale, rect.size.height * scale);
- CGImageRef imageRef = CGImageCreateWithImageInRect([self CGImage], rect);
+ CGImageRef imageRef = CGImageCreateWithImageInRect(self.CGImage, rect);
UIImage *cropped = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return cropped;
View
26 Tests/ArrayCategoryTest.m
@@ -23,4 +23,30 @@ - (void)testFirstObject {
[array release];
}
+
+- (void)testMD5Sum {
+ NSArray *array1 = [NSArray arrayWithObjects:@"value1", @"value2", @"value3", @"value4", @"value5", nil];
+ NSMutableArray *array2 = [NSMutableArray arrayWithObjects:@"value1", @"value2", @"value3", @"value4", nil];
+ [array2 addObject:@"value5"];
+
+ NSString *sum1 = [array1 MD5Sum];
+ NSString *sum2 = [array2 MD5Sum];
+ GHAssertNotNil(sum1, nil);
+ GHAssertNotNil(sum2, nil);
+ GHAssertEqualObjects(sum1, sum2, nil);
+}
+
+
+- (void)testSHA1Sum {
+ NSArray *array1 = [NSArray arrayWithObjects:@"value1", @"value2", @"value3", @"value4", @"value5", nil];
+ NSMutableArray *array2 = [NSMutableArray arrayWithObjects:@"value1", @"value2", @"value3", @"value4", nil];
+ [array2 addObject:@"value5"];
+
+ NSString *sum1 = [array1 SHA1Sum];
+ NSString *sum2 = [array2 SHA1Sum];
+ GHAssertNotNil(sum1, nil);
+ GHAssertNotNil(sum2, nil);
+ GHAssertEqualObjects(sum1, sum2, nil);
+}
+
@end
View
61 Tests/ColorCategoryTest.m
@@ -15,10 +15,67 @@ @implementation ColorCategoryTest
- (void)testAlpha {
UIColor *color = [UIColor blackColor];
- GHAssertEquals([color alpha], 1.0f, nil);
+ GHAssertEquals(color.alpha, 1.0f, nil);
color = [UIColor colorWithRed:0.3f green:0.4f blue:0.5f alpha:0.6f];
- GHAssertEquals([color alpha], 0.6f, nil);
+ GHAssertEquals(color.alpha, 0.6f, nil);
+}
+
+
+- (void)testRed {
+ UIColor *color = [UIColor redColor];
+ GHAssertEquals(color.red, 1.0f, nil);
+
+ color = [UIColor colorWithRed:0.3f green:0.4f blue:0.5f alpha:0.6f];
+ GHAssertEquals(color.red, 0.3f, nil);
+}
+
+
+- (void)testGreen {
+ UIColor *color = [UIColor greenColor];
+ GHAssertEquals(color.green, 1.0f, nil);
+
+ color = [UIColor colorWithRed:0.3f green:0.4f blue:0.5f alpha:0.6f];
+ GHAssertEquals(color.green, 0.4f, nil);
+}
+
+
+- (void)testBlue {
+ UIColor *color = [UIColor blueColor];
+ GHAssertEquals(color.blue, 1.0f, nil);
+
+ color = [UIColor colorWithRed:0.3f green:0.4f blue:0.5f alpha:0.6f];
+ GHAssertEquals(color.blue, 0.5f, nil);
+}
+
+
+- (void)testColorWithHex {
+ UIColor *red = [UIColor redColor];
+ GHAssertEqualObjects(red, [UIColor colorWithHex:@"ff0000"], nil);
+ GHAssertEqualObjects(red, [UIColor colorWithHex:@"f00"], nil);
+
+ UIColor *green = [UIColor greenColor];
+ GHAssertEqualObjects(green, [UIColor colorWithHex:@"00ff00"], nil);
+ GHAssertEqualObjects(green, [UIColor colorWithHex:@"0f0"], nil);
+
+ UIColor *blue = [UIColor blueColor];
+ GHAssertEqualObjects(blue, [UIColor colorWithHex:@"0000ff"], nil);
+ GHAssertEqualObjects(blue, [UIColor colorWithHex:@"00f"], nil);
+}
+
+
+- (void)testHexValue {
+ UIColor *red = [UIColor redColor];
+ GHAssertEqualObjects([red hexValue], @"ff0000", nil);
+
+ UIColor *green = [UIColor greenColor];
+ GHAssertEqualObjects([green hexValue], @"00ff00", nil);
+
+ UIColor *blue = [UIColor blueColor];
+ GHAssertEqualObjects([blue hexValue], @"0000ff", nil);
+
+ UIColor *white = [UIColor whiteColor];
+ GHAssertEqualObjects([white hexValue], @"ffffff", nil);
}
@end
View
50 Tests/DictionaryCategoryTest.m
@@ -32,4 +32,54 @@ - (void)testURLEncoding {
GHAssertEqualObjects([NSDictionary dictionaryWithFormEncodedString:string], dictionary, nil);
}
+
+- (void)testMD5Sum {
+ NSDictionary *dictionary1 = [NSDictionary dictionaryWithObjectsAndKeys:
+ @"value1", @"key1",
+ @"value2", @"key2",
+ @"value3", @"key3",
+ @"value4", @"key4",
+ @"value5", @"key5",
+ nil];
+
+ NSMutableDictionary *dictionary2 = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ @"value3", @"key3",
+ @"value4", @"key4",
+ @"value5", @"key5",
+ @"value1", @"key1",
+ nil];
+ [dictionary2 setObject:@"value2" forKey:@"key2"];
+
+ NSString *sum1 = [dictionary1 MD5Sum];
+ NSString *sum2 = [dictionary2 MD5Sum];
+ GHAssertNotNil(sum1, nil);
+ GHAssertNotNil(sum2, nil);
+ GHAssertEqualObjects(sum1, sum2, nil);
+}
+
+
+- (void)testSHA1Sum {
+ NSDictionary *dictionary1 = [NSDictionary dictionaryWithObjectsAndKeys:
+ @"value1", @"key1",
+ @"value2", @"key2",
+ @"value3", @"key3",
+ @"value4", @"key4",
+ @"value5", @"key5",
+ nil];
+
+ NSMutableDictionary *dictionary2 = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ @"value3", @"key3",
+ @"value4", @"key4",
+ @"value5", @"key5",
+ @"value1", @"key1",
+ nil];
+ [dictionary2 setObject:@"value2" forKey:@"key2"];
+
+ NSString *sum1 = [dictionary1 SHA1Sum];
+ NSString *sum2 = [dictionary2 SHA1Sum];
+ GHAssertNotNil(sum1, nil);
+ GHAssertNotNil(sum2, nil);
+ GHAssertEqualObjects(sum1, sum2, nil);
+}
+
@end

0 comments on commit 5f403d5

Please sign in to comment.