Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added an action button

  • Loading branch information...
commit cf455096b823a16dfe303535b9e982fd3dccd1ad 1 parent 4786248
@coneybeare coneybeare authored
View
BIN  UAModalPanel/Panel/Images/modalButton-selected.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  UAModalPanel/Panel/Images/modalButton-selected@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  UAModalPanel/Panel/Images/modalButton.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  UAModalPanel/Panel/Images/modalButton@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
4 UAModalPanel/Panel/Panels/UAModalPanel.h
@@ -22,6 +22,7 @@
@optional
- (void)willShowModalPanel:(UAModalPanel *)modalPanel;
- (void)didShowModalPanel:(UAModalPanel *)modalPanel;
+- (void)didSelectActionButton:(UAModalPanel *)modalPanel;
- (BOOL)shouldCloseModalPanel:(UAModalPanel *)modalPanel;
- (void)willCloseModalPanel:(UAModalPanel *)modalPanel;
- (void)didCloseModalPanel:(UAModalPanel *)modalPanel;
@@ -36,6 +37,7 @@ typedef void (^UAModalDisplayPanelAnimationComplete)(BOOL finished);
UIView *contentContainer;
UIView *roundedRect;
UIButton *closeButton;
+ UIButton *actionButton;
UIView *contentView;
CGPoint startEndPoint;
@@ -56,6 +58,7 @@ typedef void (^UAModalDisplayPanelAnimationComplete)(BOOL finished);
@property (nonatomic, retain) UIView *contentContainer;
@property (nonatomic, retain) UIView *roundedRect;
@property (nonatomic, retain) UIButton *closeButton;
+@property (nonatomic, retain) UIButton *actionButton;
@property (nonatomic, retain) UIView *contentView;
// Margin between edge of container frame and panel. Default = {20.0, 20.0, 20.0, 20.0}
@@ -74,6 +77,7 @@ typedef void (^UAModalDisplayPanelAnimationComplete)(BOOL finished);
@property (nonatomic, assign) BOOL shouldBounce;
@property (readwrite, copy) UAModalDisplayPanelEvent onClosePressed;
+@property (readwrite, copy) UAModalDisplayPanelEvent onActionPressed;
- (void)show;
- (void)showFromPoint:(CGPoint)point;
View
69 UAModalPanel/Panel/Panels/UAModalPanel.m
@@ -21,9 +21,9 @@
@implementation UAModalPanel
-@synthesize roundedRect, closeButton, delegate, contentView, contentContainer;
+@synthesize roundedRect, closeButton, actionButton, delegate, contentView, contentContainer;
@synthesize margin, padding, cornerRadius, borderWidth, borderColor, contentColor, shouldBounce;
-@synthesize onClosePressed;
+@synthesize onClosePressed, onActionPressed;
- (id)initWithFrame:(CGRect)frame {
@@ -32,6 +32,7 @@ - (id)initWithFrame:(CGRect)frame {
delegate = nil;
roundedRect = nil;
closeButton = nil;
+ actionButton = nil;
contentView = nil;
startEndPoint = CGPointZero;
@@ -65,6 +66,7 @@ - (id)initWithFrame:(CGRect)frame {
- (void)dealloc {
self.roundedRect = nil;
self.closeButton = nil;
+ self.actionButton = nil;
self.contentContainer = nil;
self.borderColor = nil;
self.contentColor = nil;
@@ -130,6 +132,30 @@ - (UIButton*)closeButton {
}
return closeButton;
}
+
+- (UIButton*)actionButton {
+ if (!actionButton) {
+ UIImage *image = [UIImage imageNamed:@"modalButton.png"];
+ UIImage *stretch = [image resizableImageWithCapInsets:UIEdgeInsetsMake(0, image.size.width/2.0, 0, image.size.width/2.0)];
+ UIImage *image2 = [UIImage imageNamed:@"modalButton-selected.png"];
+ UIImage *stretch2 = [image2 resizableImageWithCapInsets:UIEdgeInsetsMake(0, image2.size.width/2.0, 0, image2.size.width/2.0)];
+ self.actionButton = [UIButton buttonWithType:UIButtonTypeCustom];
+ [self.actionButton setBackgroundImage:stretch forState:UIControlStateNormal];
+ [self.actionButton setBackgroundImage:stretch2 forState:UIControlStateHighlighted];
+ self.actionButton.layer.shadowColor = [[UIColor blackColor] CGColor];
+ self.actionButton.layer.shadowOffset = CGSizeMake(0,4);
+ self.actionButton.layer.shadowOpacity = 0.3;
+ self.actionButton.titleLabel.font = [UIFont boldSystemFontOfSize:12];
+ [self.actionButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
+ [self.actionButton setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
+ self.actionButton.contentEdgeInsets = UIEdgeInsetsMake(4, 8, 4, 8);
+
+ [actionButton addTarget:self action:@selector(actionPressed:) forControlEvents:UIControlEventTouchUpInside];
+ [self.contentContainer insertSubview:actionButton aboveSubview:self.roundedRect];
+ }
+ return actionButton;
+}
+
- (UIView *)contentView {
if (!contentView) {
self.contentView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
@@ -156,6 +182,18 @@ - (CGRect)closeButtonFrame {
closeButton.frame.size.height);
}
+- (CGRect)actionButtonFrame {
+ if (![[self.actionButton titleForState:UIControlStateNormal] length])
+ return CGRectZero;
+
+ [self.actionButton sizeToFit];
+ CGRect f = [self roundedRectFrame];
+ return CGRectMake(f.origin.x + f.size.width - self.actionButton.frame.size.width + 11,
+ f.origin.y - floor(actionButton.frame.size.height*0.5),
+ self.actionButton.frame.size.width,
+ self.actionButton.frame.size.height);
+}
+
- (CGRect)contentViewFrame {
CGRect roundedRectFrame = [self roundedRectFrame];
return CGRectMake(self.padding.left + roundedRectFrame.origin.x,
@@ -168,9 +206,10 @@ - (CGRect)contentViewFrame {
- (void)layoutSubviews {
[super layoutSubviews];
- self.roundedRect.frame = [self roundedRectFrame];
- self.closeButton.frame = [self closeButtonFrame];
- self.contentView.frame = [self contentViewFrame];
+ self.roundedRect.frame = [self roundedRectFrame];
+ self.closeButton.frame = [self closeButtonFrame];
+ self.actionButton.frame = [self actionButtonFrame];
+ self.contentView.frame = [self contentViewFrame];
UADebugLog(@"roundedRect frame: %@", NSStringFromCGRect(self.roundedRect.frame));
UADebugLog(@"contentView frame: %@", NSStringFromCGRect(self.contentView.frame));
@@ -198,6 +237,25 @@ - (void)closePressed:(id)sender {
}
}
+- (void)actionPressed:(id)sender {
+
+ // Using Delegates
+ if ([delegate respondsToSelector:@selector(didSelectActionButton:)]) {
+ [delegate didSelectActionButton:self];
+
+
+ // Using blocks
+ } else if (self.onActionPressed) {
+ UADebugLog(@"Action pressed using blocks for modalPanel: %@", self);
+ self.onActionPressed(self);
+
+ // No delegate or blocks. Do nothing!
+ } else {
+ // no-op
+ }
+}
+
+
- (void)showAnimationStarting {}; //subcalsses override
- (void)showAnimationPart1Finished {}; //subcalsses override
- (void)showAnimationPart2Finished {}; //subcalsses override
@@ -305,5 +363,4 @@ - (void)hideWithOnComplete:(UAModalDisplayPanelAnimationComplete)onComplete {
}];
}
-
@end
Please sign in to comment.
Something went wrong with that request. Please try again.