Skip to content

Commit

Permalink
BackgroundShadow added
Browse files Browse the repository at this point in the history
  • Loading branch information
kubatruhlar committed Jun 17, 2015
1 parent fbbf319 commit 0ad1ab3
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 20 deletions.
81 changes: 65 additions & 16 deletions JTAlertView Example/JTAlertView Example/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions JTAlertView Example/JTAlertView Example/ViewController.h
Expand Up @@ -16,6 +16,7 @@
@property (weak, nonatomic) IBOutlet UISwitch *popSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *parallaxSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *fontSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *bgSwitch;

- (IBAction)showPressed:(id)sender;

Expand All @@ -26,6 +27,7 @@
- (IBAction)popSwitch:(id)sender;
- (IBAction)parallaxSwitch:(id)sender;
- (IBAction)fontSwitch:(id)sender;
- (IBAction)bgSwitch:(id)sender;

@end

9 changes: 9 additions & 0 deletions JTAlertView Example/JTAlertView Example/ViewController.m
Expand Up @@ -17,6 +17,7 @@ @interface ViewController ()
@property (nonatomic, strong) UIFont *customFont;
@property (nonatomic, assign) bool pop;
@property (nonatomic, assign) bool parallax;
@property (nonatomic, assign) bool bg;
@property (nonatomic, assign) NSInteger numberOfButtons;

@end
Expand All @@ -33,13 +34,15 @@ - (void)viewDidLoad {
_pop = true;
_parallax = true;
_customFont = nil;
_bg = false;

_segmentControl.selectedSegmentIndex = _numberOfButtons;
_animatedSwitch.on = _animated;
_destructiveSwitch.on = _destructive;
_popSwitch.on = _pop;
_parallaxSwitch.on = _parallax;
_fontSwitch.on = _customFont ? true : false;
_bgSwitch.on = _bg;
}

- (void)didReceiveMemoryWarning {
Expand All @@ -51,6 +54,7 @@ - (IBAction)showPressed:(id)sender {
self.alertView.size = CGSizeMake(280, 230);
self.alertView.popAnimation = _pop;
self.alertView.parallaxEffect = _parallax;
self.alertView.backgroundShadow = _bg;

__weak typeof(self)weakSelf = self;

Expand Down Expand Up @@ -152,4 +156,9 @@ - (IBAction)fontSwitch:(id)sender {
}
}

- (IBAction)bgSwitch:(id)sender {
UISwitch *bgSwitch = (UISwitch *)sender;
_bg = bgSwitch.isOn;
}

@end
9 changes: 6 additions & 3 deletions JTAlertView/JTAlertView.h
Expand Up @@ -21,10 +21,10 @@ typedef NS_ENUM(NSInteger, JTAlertViewStyle) {
@property (nonatomic, assign) CGSize size;

/** Pop animation of the alertView when shows and pressed (Disable animated show will also disable pop show animation). Default is YES. */
@property (nonatomic, assign) bool popAnimation;
@property (nonatomic, assign, getter=isPopAnimation) bool popAnimation;

/** Beautiful parallax effect of image within alertView. Default is YES. */
@property (nonatomic, assign) bool parallaxEffect;
@property (nonatomic, assign, getter=isParallaxEffect) bool parallaxEffect;

/** Image overlay. Default overlay is gray with half alpha. */
@property (nonatomic, strong) UIColor *overlayColor;
Expand All @@ -36,7 +36,10 @@ typedef NS_ENUM(NSInteger, JTAlertViewStyle) {
@property (nonatomic, strong) UIColor *titleColor;

/** Shadow underneath the title. Default is YES. */
@property (nonatomic, assign) bool titleShadow;
@property (nonatomic, assign, getter=isTitleShadow) bool titleShadow;

/** Shadow underneath the alertView. Default is NO. */
@property (nonatomic, assign, getter=isBackgroundShadow) bool backgroundShadow;

// Initializers
+ (instancetype)alertWithTitle:(NSString *)titleText andImage:(UIImage *)image;
Expand Down
23 changes: 23 additions & 0 deletions JTAlertView/JTAlertView.m
Expand Up @@ -30,6 +30,7 @@ @interface JTAlertView()
@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UITapGestureRecognizer *gestureRecognizer;
@property (nonatomic, strong) UIView *backgroundView;

@end

Expand Down Expand Up @@ -63,6 +64,9 @@ - (instancetype)initWithTitle:(NSString *)titleText andImage:(UIImage *)image {
// Notifications
[self createObservers];

// Background
[self createBackgroundView];

return self;
}

Expand Down Expand Up @@ -221,6 +225,18 @@ - (void)applyAppearanceConsideringButtons:(bool)consideringBtns {
}
}

- (void)createBackgroundView {
self.backgroundView = [[UIView alloc] initWithFrame:[UIApplication sharedApplication].keyWindow.bounds];
self.backgroundView.backgroundColor = [UIColor colorWithWhite:0.1 alpha:0.5];
self.backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.backgroundView.alpha = 0.0;
}

- (void)addBackgroundBelowAlertView {
[self.backgroundView removeFromSuperview];
[[UIApplication sharedApplication].keyWindow insertSubview:self.backgroundView belowSubview:self];
}

#pragma mark - Displaying
- (void)show {
[self showInSuperview:[[UIApplication sharedApplication] keyWindow] withCompletion:nil animated:true];
Expand Down Expand Up @@ -249,9 +265,13 @@ - (void)showInSuperview:(UIView *)superView withCompletion:(void (^)())completio
}
[superView addSubview:self];

// Add gradient
_backgroundShadow ? [self addBackgroundBelowAlertView] : nil;

// Animation
[UIView animateWithDuration:animationDuration animations:^{
[self fullAlpha];
self.backgroundView.alpha = 1.0;
_popAnimation ? [self popAnimationForView:self withDuration:animationDuration] : nil;

} completion:^(BOOL finished) {
Expand Down Expand Up @@ -280,6 +300,7 @@ - (void)hideWithCompletion:(void (^)())completion animated:(bool)animated {
animationDuration = animated ? kAnimatingDuration : 0;
[UIView animateWithDuration:animationDuration animations:^{
[self noAlpha];
self.backgroundView.alpha = 0.0;
[UIView animateWithDuration:animationDuration delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
self.transform = CGAffineTransformMakeScale(0.95, 0.95);
} completion:nil];
Expand All @@ -292,6 +313,7 @@ - (void)hideWithCompletion:(void (^)())completion animated:(bool)animated {
[self removeFromSuperview];
[_imgView removeFromSuperview];
[_titleLabel removeFromSuperview];
[self.backgroundView removeFromSuperview];
if (completion) {
completion();
}
Expand Down Expand Up @@ -336,6 +358,7 @@ - (void)defaultSetup {
_font = [UIFont fontWithName:@"HelveticaNeue-Medium" size:kTitleFontSize];
_titleColor = [UIColor whiteColor];
_titleShadow = true;
_backgroundShadow = false;
}

- (void)noAlpha {
Expand Down
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -46,7 +46,7 @@ self.alertView.size = CGSizeMake(280, 230);
### Properties:
You must setup `size` property or the default will be used. `popAnimation` is visible while displaying and if you tap on the dialog. The `overlayColor` above given image and decent `titleShadow` make title better readable. The `font` property (it's `style` and `size`) is applied to title and buttons (`style` only). To customize particular buttons, use `font` parameter in buttons adding methods (*see below*).
You must setup `size` property or the default will be used. `popAnimation` is visible while displaying and if you tap on the dialog. The `overlayColor` above given image and decent `titleShadow` make title better readable. The `backgroundShadow` creates decent shadow under the alertView. The `font` property (it's `style` and `size`) is applied to title and buttons (`style` only). To customize particular buttons, use `font` parameter in buttons adding methods (*see below*).
```objective-c
@property (nonatomic, assign) CGSize size;
Expand All @@ -58,6 +58,7 @@ You must setup `size` property or the default will be used. `popAnimation` is vi
@property (nonatomic, strong) UIFont *font;
@property (nonatomic, strong) UIColor *titleColor;
@property (nonatomic, assign) bool titleShadow;
@property (nonatomic, assign) bool backgroundShadow;
```


Expand Down Expand Up @@ -89,6 +90,9 @@ You can show **JTAlertView** `withCompletion` block, in specific `superview`, `a

## Changelog

### v1.0.1 - 06.18.15
- [**NEW**] BackgroundShadow added

### v1.0.0 - 06.17.15
- [**NEW**] Initial commit

Expand Down

0 comments on commit 0ad1ab3

Please sign in to comment.