Permalink
Browse files

Add `initWithCoder:` to views to allow for use in Interface Builder. F…

…ixes #63
  • Loading branch information...
1 parent 569df34 commit 5b58afc3fd2bfad4c4fbd37a6a75e441e6429717 @soffes soffes committed Oct 9, 2011
@@ -11,6 +11,10 @@
#import "SSDrawingUtilities.h"
#import "UIImage+SSToolkitAdditions.h"
+@interface SSAddressBarTextField ()
+- (void)_initialize;
+@end
+
@implementation SSAddressBarTextField {
SSAddressBarTextFieldBackgroundView *_textFieldBackgroundView;
}
@@ -45,43 +49,17 @@ - (void)dealloc {
#pragma mark - UIView
+- (id)initWithCoder:(NSCoder *)aDecoder {
+ if ((self = [super initWithCoder:aDecoder])) {
+ [self _initialize];
+ }
+ return self;
+}
+
+
- (id)initWithFrame:(CGRect)aFrame {
if ((self = [super initWithFrame:aFrame])) {
-
- // Configure text field
- self.borderStyle = UITextBorderStyleRoundedRect;
- self.textColor = [UIColor colorWithWhite:0.180f alpha:1.0f];
- self.font = [UIFont systemFontOfSize:15.0f];
- self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
- self.autocapitalizationType = UITextAutocapitalizationTypeNone;
- self.autocorrectionType = UITextAutocorrectionTypeNo;
- self.keyboardType = UIKeyboardTypeURL;
- self.returnKeyType = UIReturnKeyGo;
- self.clearButtonMode = UITextFieldViewModeWhileEditing;
- self.enablesReturnKeyAutomatically = YES;
- self.rightViewMode = UITextFieldViewModeUnlessEditing;
- self.textEdgeInsets = UIEdgeInsetsMake(0.0f, 5.0f, 0.0f, 26.0f);
-
- // Background view
- _textFieldBackgroundView = [[SSAddressBarTextFieldBackgroundView alloc] initWithFrame:CGRectZero];
- [self insertSubview:_textFieldBackgroundView aboveSubview:[[self subviews] objectAtIndex:0]];
-
- // Refresh button
- UIButton *aReloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
- aReloadButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
- aReloadButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
- [aReloadButton setImage:[UIImage imageNamed:@"SSAddressBarTextFieldReload.png" bundleName:kSSToolkitBundleName] forState:UIControlStateNormal];
- self.reloadButton = aReloadButton;
- self.rightView = _reloadButton;
-
- // Stop button
- UIButton *aStopButton = [UIButton buttonWithType:UIButtonTypeCustom];
- aStopButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
- aStopButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
- [aStopButton setImage:[UIImage imageNamed:@"SSAddressBarTextFieldStop.png" bundleName:kSSToolkitBundleName] forState:UIControlStateNormal];
- self.stopButton = aStopButton;
-
- self.loading = NO;
+ [self _initialize];
}
return self;
}
@@ -102,4 +80,44 @@ - (CGRect)rightViewRectForBounds:(CGRect)bounds {
return CGRectMake(size.width - 24.0f, roundf((size.height - 18.0f) / 2.0f), 16.0f, 18.0f);
}
+
+#pragma mark - Private
+
+- (void)_initialize {
+ // Configure text field
+ self.borderStyle = UITextBorderStyleRoundedRect;
+ self.textColor = [UIColor colorWithWhite:0.180f alpha:1.0f];
+ self.font = [UIFont systemFontOfSize:15.0f];
+ self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
+ self.autocapitalizationType = UITextAutocapitalizationTypeNone;
+ self.autocorrectionType = UITextAutocorrectionTypeNo;
+ self.keyboardType = UIKeyboardTypeURL;
+ self.returnKeyType = UIReturnKeyGo;
+ self.clearButtonMode = UITextFieldViewModeWhileEditing;
+ self.enablesReturnKeyAutomatically = YES;
+ self.rightViewMode = UITextFieldViewModeUnlessEditing;
+ self.textEdgeInsets = UIEdgeInsetsMake(0.0f, 5.0f, 0.0f, 26.0f);
+
+ // Background view
+ _textFieldBackgroundView = [[SSAddressBarTextFieldBackgroundView alloc] initWithFrame:CGRectZero];
+ [self insertSubview:_textFieldBackgroundView aboveSubview:[[self subviews] objectAtIndex:0]];
+
+ // Refresh button
+ UIButton *aReloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
+ aReloadButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
+ aReloadButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
+ [aReloadButton setImage:[UIImage imageNamed:@"SSAddressBarTextFieldReload.png" bundleName:kSSToolkitBundleName] forState:UIControlStateNormal];
+ self.reloadButton = aReloadButton;
+ self.rightView = _reloadButton;
+
+ // Stop button
+ UIButton *aStopButton = [UIButton buttonWithType:UIButtonTypeCustom];
+ aStopButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
+ aStopButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
+ [aStopButton setImage:[UIImage imageNamed:@"SSAddressBarTextFieldStop.png" bundleName:kSSToolkitBundleName] forState:UIControlStateNormal];
+ self.stopButton = aStopButton;
+
+ self.loading = NO;
+}
+
@end
View
@@ -10,13 +10,23 @@
#import "SSLabel.h"
#import "SSDrawingUtilities.h"
+@interface SSBadgeView ()
+- (void)_initialize;
+@end
+
@implementation SSBadgeView
#pragma mark - Accessors
@synthesize textLabel = _textLabel;
@synthesize badgeColor = _badgeColor;
+@synthesize highlightedBadgeColor = _highlightedBadgeColor;
+@synthesize badgeImage = _badgeImage;
+@synthesize highlightedBadgeImage = _highlightedBadgeImage;
+@synthesize cornerRadius = _cornerRadius;
+@synthesize badgeAlignment = _badgeAlignment;
+@synthesize highlighted = _highlighted;
- (void)setBadgeColor:(UIColor *)badgeColor {
[badgeColor retain];
@@ -27,8 +37,6 @@ - (void)setBadgeColor:(UIColor *)badgeColor {
}
-@synthesize highlightedBadgeColor = _highlightedBadgeColor;
-
- (void)setHighlightedBadgeColor:(UIColor *)highlightedBadgeColor {
[highlightedBadgeColor retain];
[_highlightedBadgeColor release];
@@ -37,7 +45,6 @@ - (void)setHighlightedBadgeColor:(UIColor *)highlightedBadgeColor {
[self setNeedsDisplay];
}
-@synthesize badgeImage = _badgeImage;
- (void)setBadgeImage:(UIImage *)badgeImage {
[badgeImage retain];
@@ -47,7 +54,6 @@ - (void)setBadgeImage:(UIImage *)badgeImage {
[self setNeedsDisplay];
}
-@synthesize highlightedBadgeImage = _highlightedBadgeImage;
- (void)setHighlightedBadgeImage:(UIImage *)highlightedBadgeImage {
[highlightedBadgeImage retain];
@@ -58,26 +64,20 @@ - (void)setHighlightedBadgeImage:(UIImage *)highlightedBadgeImage {
}
-@synthesize cornerRadius = _cornerRadius;
-
- (void)setCornerRadius:(CGFloat)cornerRadius {
_cornerRadius = cornerRadius;
[self setNeedsDisplay];
}
-@synthesize badgeAlignment = _badgeAlignment;
-
- (void)setBadgeAlignment:(SSBadgeViewAlignment)badgeAlignment {
_badgeAlignment = badgeAlignment;
[self setNeedsDisplay];
}
-@synthesize highlighted = _highlighted;
-
- (void)setHighlighted:(BOOL)highlighted {
_highlighted = highlighted;
_textLabel.highlighted = highlighted;
@@ -107,23 +107,17 @@ - (void)dealloc {
#pragma mark - UIView
+- (id)initWithCoder:(NSCoder *)aDecoder {
+ if ((self = [super initWithCoder:aDecoder])) {
+ [self _initialize];
+ }
+ return self;
+}
+
+
- (id)initWithFrame:(CGRect)rect {
if ((self = [super initWithFrame:rect])) {
- self.backgroundColor = [UIColor whiteColor];
- self.opaque = YES;
-
- _textLabel = [[SSLabel alloc] initWithFrame:CGRectZero];
- _textLabel.text = @"0";
- _textLabel.textColor = [UIColor whiteColor];
- _textLabel.highlightedTextColor = [UIColor colorWithRed:0.125f green:0.369f blue:0.871f alpha:1.0f];
- _textLabel.font = [UIFont boldSystemFontOfSize:16.0f];
- _textLabel.textAlignment = UITextAlignmentCenter;
-
- self.badgeColor = [[self class] defaultBadgeColor];
- self.highlightedBadgeColor = [UIColor whiteColor];
- self.cornerRadius = 10.0f;
- self.badgeAlignment = SSBadgeViewAlignmentCenter;
- self.highlighted = NO;
+ [self _initialize];
}
return self;
}
@@ -191,6 +185,27 @@ - (void)willMoveToSuperview:(UIView *)newSuperview {
}
+#pragma mark - Private
+
+- (void)_initialize {
+ self.backgroundColor = [UIColor whiteColor];
+ self.opaque = YES;
+
+ _textLabel = [[SSLabel alloc] initWithFrame:CGRectZero];
+ _textLabel.text = @"0";
+ _textLabel.textColor = [UIColor whiteColor];
+ _textLabel.highlightedTextColor = [UIColor colorWithRed:0.125f green:0.369f blue:0.871f alpha:1.0f];
+ _textLabel.font = [UIFont boldSystemFontOfSize:16.0f];
+ _textLabel.textAlignment = UITextAlignmentCenter;
+
+ self.badgeColor = [[self class] defaultBadgeColor];
+ self.highlightedBadgeColor = [UIColor whiteColor];
+ self.cornerRadius = 10.0f;
+ self.badgeAlignment = SSBadgeViewAlignmentCenter;
+ self.highlighted = NO;
+}
+
+
#pragma mark - NSKeyValueObserving
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
View
@@ -14,6 +14,10 @@ @implementation SSBorderedView
#pragma mark - Accessors
@synthesize topBorderColor = _topBorderColor;
+@synthesize topInsetColor = _topInsetColor;
+@synthesize bottomInsetColor = _bottomInsetColor;
+@synthesize bottomBorderColor = _bottomBorderColor;
+
- (void)setTopBorderColor:(UIColor *)topBorderColor {
[topBorderColor retain];
@@ -24,8 +28,6 @@ - (void)setTopBorderColor:(UIColor *)topBorderColor {
}
-@synthesize topInsetColor = _topInsetColor;
-
- (void)setTopInsetColor:(UIColor *)topInsetColor {
[topInsetColor retain];
[_topInsetColor release];
@@ -35,8 +37,6 @@ - (void)setTopInsetColor:(UIColor *)topInsetColor {
}
-@synthesize bottomInsetColor = _bottomInsetColor;
-
- (void)setBottomInsetColor:(UIColor *)bottomInsetColor {
[bottomInsetColor retain];
[_bottomInsetColor release];
@@ -46,8 +46,6 @@ - (void)setBottomInsetColor:(UIColor *)bottomInsetColor {
}
-@synthesize bottomBorderColor = _bottomBorderColor;
-
- (void)setBottomBorderColor:(UIColor *)bottomBorderColor {
[bottomBorderColor retain];
[_bottomBorderColor release];
@@ -31,6 +31,7 @@
static NSString *kSSCollectionViewSectionItemSizeKey = @"SSCollectionViewSectionItemSize";
@interface SSCollectionView (PrivateMethods)
+- (void)_initialize;
- (void)_reuseItem:(SSCollectionViewItem *)item;
- (void)_reuseItems:(NSArray *)items;
@@ -162,24 +163,17 @@ - (void)dealloc {
#pragma mark - UIView
+- (id)initWithCoder:(NSCoder *)aDecoder {
+ if ((self = [super initWithCoder:aDecoder])) {
+ [self _initialize];
+ }
+ return self;
+}
+
+
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
- self.backgroundColor = [UIColor whiteColor];
- self.opaque = YES;
-
- _minimumColumnSpacing = 10.0f;
- _rowSpacing = 20.0f;
- _allowsSelection = YES;
- _visibleItems = [[NSMutableSet alloc] init];
- _reuseableItems = [[NSMutableDictionary alloc] init];
- _sectionCache = [[NSMutableDictionary alloc] init];
-
- _tableView = [[UITableView alloc] initWithFrame:self.bounds];
- _tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- _tableView.dataSource = self;
- _tableView.delegate = self;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- [self addSubview:_tableView];
+ [self _initialize];
}
return self;
}
@@ -347,6 +341,26 @@ - (CGRect)rectForFooterInSection:(NSUInteger)section {
#pragma mark - Private Methods
+- (void)_initialize {
+ self.backgroundColor = [UIColor whiteColor];
+ self.opaque = YES;
+
+ _minimumColumnSpacing = 10.0f;
+ _rowSpacing = 20.0f;
+ _allowsSelection = YES;
+ _visibleItems = [[NSMutableSet alloc] init];
+ _reuseableItems = [[NSMutableDictionary alloc] init];
+ _sectionCache = [[NSMutableDictionary alloc] init];
+
+ _tableView = [[UITableView alloc] initWithFrame:self.bounds];
+ _tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+ _tableView.dataSource = self;
+ _tableView.delegate = self;
+ _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
+ [self addSubview:_tableView];
+}
+
+
- (void)_reuseItem:(SSCollectionViewItem *)item {
[_visibleItems removeObject:item];
Oops, something went wrong.

0 comments on commit 5b58afc

Please sign in to comment.