Permalink
Browse files

Opened up many internal variables for further customization

  • Loading branch information...
1 parent 00c6df3 commit c430d5d4c30a66047b65e39d93418360a961592f @coneybeare coneybeare committed Jan 11, 2012
@@ -131,10 +131,7 @@ - (void)drawRect:(CGRect)rect {
- (void)dealloc {
NSZoneFree(NSDefaultMallocZone(), colorComponents);
-// DebugLog(@"FUCK: self.tag = %d, self = %@", self.tag, self);
- @try {
- [super dealloc];
- } @catch (NSException *e) {} // bandaid
+ [super dealloc];
}
@@ -17,12 +17,15 @@
UIButton *closeButton;
UIView *contentView;
- CGFloat margin;
-
CGPoint startEndPoint;
-
CGRect innerFrame;
+ CGFloat outerMargin;
+ CGFloat innerMargin;
+ UIColor *borderColor;
+ CGFloat borderWidth;
+ CGFloat cornerRadius;
+ UIColor *contentColor;
BOOL shouldBounce;
}
@@ -32,7 +35,20 @@
@property (nonatomic, retain) UIView *roundedRect;
@property (nonatomic, retain) UIButton *closeButton;
@property (nonatomic, retain) UIView *contentView;
-@property (nonatomic, assign) CGFloat margin;
+
+// Margin between edge of container frame and panel. Default = 20.0
+@property (nonatomic, assign) CGFloat outerMargin;
+// Margin between edge of panel and the content area. Default = 20.0
+@property (nonatomic, assign) CGFloat innerMargin;
+// Border color of the panel. Default = [UIColor whiteColor]
+@property (nonatomic, retain) UIColor *borderColor;
+// Border width of the panel. Default = 1.5f
+@property (nonatomic, assign) CGFloat borderWidth;
+// Corner radius of the panel. Default = 4.0f
+@property (nonatomic, assign) CGFloat cornerRadius;
+// Color of the panel itself. Default = [UIColor colorWithWhite:0.0 alpha:0.8]
+@property (nonatomic, retain) UIColor *contentColor;
+// Shows the bounce animation. Default = YES
@property (nonatomic, assign) BOOL shouldBounce;
- (void)show;
@@ -12,15 +12,20 @@
#import "UAModalPanel.h"
#import "UARoundedRectView.h"
-#define DEFAULT_MARGIN 20
-
+#define DEFAULT_MARGIN 20.0f
+#define DEFAULT_BACKGROUND_COLOR [UIColor colorWithWhite:0.0 alpha:0.8]
+#define DEFAULT_CORNER_RADIUS 4.0f
+#define DEFAULT_BORDER_WIDTH 1.5f
+#define DEFAULT_BORDER_COLOR [UIColor whiteColor]
+#define DEFAULT_BOUNCE YES
@implementation UAModalPanel
-@synthesize roundedRect, closeButton, delegate, contentView, contentContainer, shouldBounce, margin;
+@synthesize roundedRect, closeButton, delegate, contentView, contentContainer;
+@synthesize innerMargin, outerMargin, cornerRadius, borderWidth, borderColor, contentColor, shouldBounce;
- (void)calculateInnerFrame {
- //adjust the popup frame for iPad if it is too big.
+ //adjust the popup frame here for iPad if it is too big.
innerFrame = self.frame;
}
@@ -34,43 +39,80 @@ - (id)initWithFrame:(CGRect)frame {
contentView = nil;
startEndPoint = CGPointZero;
+ outerMargin = DEFAULT_MARGIN;
+ innerMargin = DEFAULT_MARGIN;
+ cornerRadius = DEFAULT_CORNER_RADIUS;
+ borderWidth = DEFAULT_BORDER_WIDTH;
+ borderColor = [DEFAULT_BORDER_COLOR retain];
+ contentColor = [DEFAULT_BACKGROUND_COLOR retain];
+ shouldBounce = DEFAULT_BOUNCE;
+
+ self.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
+ self.autoresizesSubviews = YES;
+
self.contentContainer = [[[UIView alloc] initWithFrame:self.bounds] autorelease];
self.contentContainer.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
self.contentContainer.autoresizesSubviews = YES;
[self addSubview:self.contentContainer];
- [self setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0.5]];
- self.roundedRect.hidden = NO; // init.
- self.closeButton.hidden = NO; // init.
- [self.contentView setBackgroundColor:[UIColor clearColor]];
- self.delegate = nil;
+ [self setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0.5]]; // Fixed, the bacground mask.
- self.margin = DEFAULT_MARGIN;
+// self.roundedRect.hidden = NO; // init.
+// self.closeButton.hidden = NO; // init.
- self.shouldBounce = YES;
+ [self.contentView setBackgroundColor:[UIColor clearColor]];
+ self.delegate = nil;
+
}
return self;
}
-- (void) dealloc {
+- (void)dealloc {
self.roundedRect = nil;
self.closeButton = nil;
self.contentContainer = nil;
+ self.borderColor = nil;
+ self.contentColor = nil;
delegate = nil;
[super dealloc];
}
+#pragma mark - Accessors
+
+- (void)setCornerRadius:(CGFloat)newRadius {
+ cornerRadius = newRadius;
+ self.roundedRect.layer.cornerRadius = cornerRadius;
+}
+- (void)setBorderWidth:(CGFloat)newWidth {
+ borderWidth = newWidth;
+ self.roundedRect.layer.borderWidth = borderWidth;
+}
+- (void)setBorderColor:(UIColor *)newColor {
+ [newColor retain];
+ [borderColor release];
+ borderColor = newColor;
+
+ self.roundedRect.layer.borderColor = [borderColor CGColor];
+}
+- (void)setContentColor:(UIColor *)newColor {
+ [newColor retain];
+ [contentColor release];
+ contentColor = newColor;
+
+ self.roundedRect.backgroundColor = contentColor;
+}
+
- (UIView *)roundedRect {
if (!roundedRect) {
self.roundedRect = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
- roundedRect.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.8];
- roundedRect.layer.cornerRadius = 4.0f;
roundedRect.layer.masksToBounds = YES;
- roundedRect.layer.borderColor = [[UIColor whiteColor] CGColor];
- roundedRect.layer.borderWidth = 1.5f;
+ roundedRect.backgroundColor = self.contentColor;
+ roundedRect.layer.borderColor = [self.borderColor CGColor];
+ roundedRect.layer.borderWidth = self.borderWidth;
+ roundedRect.layer.cornerRadius = self.cornerRadius;
- [self.contentContainer addSubview:roundedRect];
+ [self.contentContainer insertSubview:roundedRect atIndex:0];
}
return roundedRect;
}
@@ -82,10 +124,9 @@ - (UIButton*)closeButton {
self.closeButton.layer.shadowColor = [[UIColor blackColor] CGColor];
self.closeButton.layer.shadowOffset = CGSizeMake(0,4);
self.closeButton.layer.shadowOpacity = 0.3;
-
[closeButton addTarget:self action:@selector(closePressed:) forControlEvents:UIControlEventTouchUpInside];
- [self.contentContainer addSubview:closeButton];
+ [self.contentContainer insertSubview:closeButton aboveSubview:self.roundedRect];
}
return closeButton;
}
@@ -103,10 +144,10 @@ - (CGRect)roundedRectFrame {
[self calculateInnerFrame];
CGFloat x = (self.frame.origin.x + floor((self.frame.size.width - innerFrame.size.width)/2));
CGFloat y = (self.frame.origin.y + floor((self.frame.size.height - innerFrame.size.height)/2));
- return CGRectMake(x + margin,
- y + margin,
- innerFrame.size.width - 2*margin,
- innerFrame.size.height - 2*margin);
+ return CGRectMake(x + self.outerMargin,
+ y + self.outerMargin,
+ innerFrame.size.width - 2*self.outerMargin,
+ innerFrame.size.height - 2*self.outerMargin);
}
- (CGRect)closeButtonFrame {
@@ -118,7 +159,7 @@ - (CGRect)closeButtonFrame {
}
- (CGRect)contentViewFrame {
- CGRect rect = CGRectInset([self roundedRectFrame], margin, margin);
+ CGRect rect = CGRectInset([self roundedRectFrame], self.innerMargin, self.innerMargin);
return rect;
}
@@ -152,7 +193,7 @@ - (void)show {
self.contentContainer.transform = CGAffineTransformMakeScale(0.00001, 0.00001);
- void (^animationBlock)(BOOL) = ^(BOOL finished){
+ void (^animationBlock)(BOOL) = ^(BOOL finished) {
[self showAnimationPart1Finished];
// Wait one second and then fade in the view
[UIView animateWithDuration:0.1
@@ -189,7 +230,7 @@ - (void)show {
animations:^{
self.alpha = 1.0;
self.contentContainer.center = self.center;
- self.contentContainer.transform = CGAffineTransformMakeScale((shouldBounce?1.05:1.0), (shouldBounce?1.05:1.0));
+ self.contentContainer.transform = CGAffineTransformMakeScale((shouldBounce ? 1.05 : 1.0), (shouldBounce ? 1.05 : 1.0));
}
completion:(shouldBounce ? animationBlock : ^(BOOL finished) {
[self showAnimationFinished];
@@ -12,12 +12,17 @@
@interface UATitledModalPanel : UAModalPanel {
+ CGFloat titleBarHeight;
UANoisyGradientBackground *titleBar;
UILabel *headerLabel;
}
+// Height of the title view. Default = 40.0f
+@property (nonatomic, assign) CGFloat titleBarHeight;
+// The gradient bacground of the title
@property (nonatomic, retain) UANoisyGradientBackground *titleBar;
+// The title label
@property (nonatomic, retain) UILabel *headerLabel;
- (CGRect)titleBarFrame;
@@ -9,9 +9,11 @@
#import "UATitledModalPanel.h"
#import <QuartzCore/QuartzCore.h>
+#define DEFAULT_TITLE_BAR_HEIGHT 40.0f
+
@implementation UATitledModalPanel
-@synthesize titleBar, headerLabel;
+@synthesize titleBarHeight, titleBar, headerLabel;
- (void)dealloc {
self.titleBar = nil;
@@ -23,6 +25,8 @@ - (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
+ self.titleBarHeight = DEFAULT_TITLE_BAR_HEIGHT;
+
CGFloat colors[8] = { 1, 1, 1, 1, 0, 0, 0, 1 };
self.titleBar = [UANoisyGradientBackground gradientWithFrame:CGRectZero
style:UAGradientBackgroundStyleLinear
@@ -47,26 +51,26 @@ - (id)initWithFrame:(CGRect)frame {
return self;
}
-#define TITLE_BAR_SIZE 40
-- (CGRect)titleBarFrame {
+
+- (CGRect)titleBarFrame {
CGRect frame = [self.roundedRect bounds];
return CGRectMake(frame.origin.x,
frame.origin.y + self.roundedRect.layer.borderWidth,
frame.size.width,
- TITLE_BAR_SIZE - self.roundedRect.layer.borderWidth);
+ self.titleBarHeight - self.roundedRect.layer.borderWidth);
}
// overriding the subclass to make room for the title bar
- (CGRect)contentViewFrame {
CGRect titleBarFrame = [self titleBarFrame];
CGRect roundedRectFrame = [self roundedRectFrame];
- CGFloat y = self.margin + titleBarFrame.origin.y + titleBarFrame.size.height;
- CGRect rect = CGRectMake(2 * self.margin,
- y,
- roundedRectFrame.size.width - 2*self.margin,
- roundedRectFrame.size.height - y);
+ CGFloat y = titleBarFrame.origin.y + titleBarFrame.size.height;
+ CGRect rect = CGRectMake(self.outerMargin + self.innerMargin,
+ self.outerMargin + self.innerMargin + y,
+ roundedRectFrame.size.width - 2*self.innerMargin,
+ roundedRectFrame.size.height - y - 2*self.innerMargin);
return rect;
}
@@ -40,12 +40,46 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
- (IBAction)showModalPanel:(id)sender {
self.currentPanel = [[[UAExampleModalPanel alloc] initWithFrame:self.view.bounds title:[(UIButton *)sender titleForState:UIControlStateNormal]] autorelease];
-
- self.currentPanel.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
- self.currentPanel.autoresizesSubviews = YES;
self.currentPanel.delegate = self;
- self.currentPanel.margin = 20;
- self.currentPanel.shouldBounce = YES;
+
+
+ // Show the defaults mostly, but once in awhile show a funky one
+ if (arc4random() % 5 == 4) {
+ // Funky time.
+
+ // Margin between edge of container frame and panel. Default = 20.0
+ self.currentPanel.outerMargin = 30.0f; // Default = 20.0f;
+
+ // Margin between edge of panel and the content area. Default = 20.0
+ self.currentPanel.innerMargin = 30.0f; // Default = 20.0f;
+
+ // Border color of the panel. Default = [UIColor whiteColor]
+ self.currentPanel.borderColor = [UIColor blueColor];
+
+ // Border width of the panel. Default = 1.5f;
+ self.currentPanel.borderWidth = 5.0f;
+
+ // Corner radius of the panel. Default = 4.0f
+ self.currentPanel.cornerRadius = 10.0f;
+
+ // Color of the panel itself. Default = [UIColor colorWithWhite:0.0 alpha:0.8]
+ self.currentPanel.contentColor = [UIColor yellowColor];
+
+ // Shows the bounce animation. Default = YES
+ self.currentPanel.shouldBounce = NO;
+
+ // Height of the title view. Default = 40.0f
+ [(UATitledModalPanel *)self.currentPanel setTitleBarHeight:80.0f];
+
+ // The background color gradient of the title
+ CGFloat colors[8] = {0, 0, 1, 1, 1, 0, 0, 1};
+ [[(UATitledModalPanel *)self.currentPanel titleBar] setColorComponents:colors];
+
+ // The header label, a UILabel with the same frame as the titleBar
+ [(UATitledModalPanel *)self.currentPanel headerLabel].font = [UIFont boldSystemFontOfSize:48];
+ }
+
+
[self.view addSubview:self.currentPanel];
[self.currentPanel showFromPoint:[sender center]];

0 comments on commit c430d5d

Please sign in to comment.