Skip to content

Commit 5bf1b3f

Browse files
committed
Merge branch 'master' of github.com:wimagguc/ios-custom-alertview
2 parents ed84129 + eff5bd4 commit 5bf1b3f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

CustomIOSAlertView/CustomIOSAlertView/View/CustomIOSAlertView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
@property (nonatomic, assign) id<CustomIOSAlertViewDelegate> delegate;
2727
@property (nonatomic, retain) NSArray *buttonTitles;
2828
@property (nonatomic, assign) BOOL useMotionEffects;
29+
@property (nonatomic, assign) BOOL closeOnTouchUpOutside; // Closes the AlertView when finger is lifted outside the bounds.
2930

3031
@property (copy) void (^onButtonTouchUpInside)(CustomIOSAlertView *alertView, int buttonIndex) ;
3132

CustomIOSAlertView/CustomIOSAlertView/View/CustomIOSAlertView.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ @implementation CustomIOSAlertView
2626
@synthesize delegate;
2727
@synthesize buttonTitles;
2828
@synthesize useMotionEffects;
29+
@synthesize closeOnTouchUpOutside;
2930

3031
- (id)initWithParentView: (UIView *)_parentView
3132
{
@@ -45,6 +46,7 @@ - (id)init
4546

4647
delegate = self;
4748
useMotionEffects = false;
49+
closeOnTouchUpOutside = false;
4850
buttonTitles = @[@"Close"];
4951

5052
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
@@ -445,4 +447,15 @@ - (void)keyboardWillHide: (NSNotification *)notification
445447
];
446448
}
447449

450+
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
451+
if (!closeOnTouchUpOutside) {
452+
return;
453+
}
454+
455+
UITouch *touch = [touches anyObject];
456+
if ([touch.view isKindOfClass:[CustomIOSAlertView class]]) {
457+
[self close];
458+
}
459+
}
460+
448461
@end

0 commit comments

Comments
 (0)