Browse files

added blocks interface, narrowed button... need to make button size d…

…ynamic
  • Loading branch information...
1 parent 058af5a commit 0852c2bf162b45b893e3eff41e7ad948c44560d1 @coryalder coryalder committed Nov 10, 2010
Showing with 44 additions and 7 deletions.
  1. +2 −0 .gitattributes
  2. +11 −0 .gitignore
  3. +9 −0 Classes/ZIStoreButton.h
  4. +22 −7 Classes/ZIStoreButton.m
View
2 .gitattributes
@@ -0,0 +1,2 @@
+*.pbxproj -crlf -diff -merge
+
View
11 .gitignore
@@ -0,0 +1,11 @@
+# xcode noise
+build/*
+*.pbxuser
+*.mode1v3
+
+# old skool
+.svn
+
+# osx noise
+.DS_Store
+profile
View
9 Classes/ZIStoreButton.h
@@ -25,10 +25,19 @@
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
+#define ZI_BUY_NOW_TITLE @"Buy Now"
+#define ZI_PRICE_TITLE @"$0.99"
+
+typedef void (^ActionBlock)();
+
@interface ZIStoreButton : UIButton
{
CAGradientLayer *innerLayer3;
BOOL isBlued;
+ ActionBlock _actionBlock;
}
+-(void)setBuyBlock:(ActionBlock)action;
+
+
@end
View
29 Classes/ZIStoreButton.m
@@ -24,21 +24,30 @@
#import "ZIStoreButton.h"
+
+
@implementation ZIStoreButton
+-(void)setBuyBlock:(ActionBlock) action {
+ _actionBlock = Block_copy(action);
+}
+
+-(void) callActionBlock:(id)sender{
+ _actionBlock();
+}
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Initialization code
-
+ _actionBlock = nil;
self.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.autoresizesSubviews = YES;
self.layer.needsDisplayOnBoundsChange = YES;
isBlued = NO;
- [self setTitle:@"Purchase Now" forState:UIControlStateSelected];
+ [self setTitle:ZI_BUY_NOW_TITLE forState:UIControlStateSelected];
[self setTitleShadowColor:[UIColor colorWithWhite:0.200 alpha:1.000] forState:UIControlStateNormal];
[self setTitleShadowColor:[UIColor colorWithWhite:0.200 alpha:1.000] forState:UIControlStateSelected];
[self.titleLabel setShadowOffset:CGSizeMake(0.0, -0.6)];
@@ -119,18 +128,21 @@ - (void) setSelected:(BOOL)selected {
[innerLayer3 layoutIfNeeded];
[innerLayer3 addAnimation:animation forKey:@"changeToBlue"];
+
for (CALayer *la in self.layer.sublayers) {
CGRect cr = la.bounds;
- cr.size.width = (!self.selected) ? cr.size.width - 50.0 : cr.size.width + 50.0;
+ cr.size.width = cr.size.width;
+ //cr.size.width = (!self.selected) ? cr.size.width - 50.0 : cr.size.width + 50.0;
la.bounds = cr;
[la layoutIfNeeded];
}
CGRect cr = self.frame;
- cr.size.width = (!self.selected) ? cr.size.width - 50.0 : cr.size.width + 50.0;
+ cr.size.width = cr.size.width;
+ //cr.size.width = (!self.selected) ? cr.size.width - 50.0 : cr.size.width + 50.0;
self.frame = cr;
- self.titleEdgeInsets = (!self.selected) ? UIEdgeInsetsMake(2.0, 0.0, 0.0, 0.0) : UIEdgeInsetsMake(2.0, -50.0, 0.0, 0.0);
+ //self.titleEdgeInsets = (!self.selected) ? UIEdgeInsetsMake(2.0, 0.0, 0.0, 0.0) : UIEdgeInsetsMake(2.0, -50.0, 0.0, 0.0);
[CATransaction commit];
}
@@ -144,23 +156,26 @@ - (IBAction) touchedUpOutside:(id)sender {
- (IBAction) pressButton:(id)sender {
if (isBlued) {
+ [self callActionBlock:sender];
[sender setSelected:NO];
isBlued = NO;
} else {
+
[sender setSelected:YES];
isBlued = YES;
}
}
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
-
+#ifdef DEBUG
NSLog(@"Animation Did Stop");
-
+#endif
}
- (void)dealloc {
+ Block_release(_actionBlock);
[super dealloc];
}

0 comments on commit 0852c2b

Please sign in to comment.