Skip to content
This repository has been archived by the owner on Apr 27, 2019. It is now read-only.

Commit

Permalink
blurStyle updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Carson Perrotti committed Oct 29, 2014
1 parent 50bf262 commit e4ef5e8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Example/CNPGridMenu/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>170</string>
<string>180</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
Expand Down
8 changes: 7 additions & 1 deletion Source/CNPGridMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@

#import <UIKit/UIKit.h>

typedef NS_ENUM(NSInteger, CNPBlurEffectStyle) {
CNPBlurEffectStyleExtraLight,
CNPBlurEffectStyleLight,
CNPBlurEffectStyleDark
};

@class CNPGridMenuItem;
@protocol CNPGridMenuDelegate;

typedef void (^SelectionHandler)(CNPGridMenuItem *item);

@interface CNPGridMenu : UICollectionViewController

@property (nonatomic, assign) UIBlurEffectStyle blurEffectStyle;
@property (nonatomic, assign) CNPBlurEffectStyle blurEffectStyle;

@property (nonatomic, weak) id <CNPGridMenuDelegate> delegate;
@property (nonatomic, readonly) NSArray *menuItems;
Expand Down
62 changes: 46 additions & 16 deletions Source/CNPGridMenu.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ @interface CNPGridMenuCell : UICollectionViewCell
@property (nonatomic, strong) UIButton *circleButton;
@property (nonatomic, strong) UIImageView *iconView;
@property (nonatomic, strong) UIView *vibrancyView;
@property (nonatomic, assign) UIBlurEffectStyle blurEffectStyle;
@property (nonatomic, assign) CNPBlurEffectStyle blurEffectStyle;

@property (nonatomic, weak) id <CNPGridMenuButtonDelegate> delegate;

Expand All @@ -63,7 +63,7 @@ - (instancetype)initWithMenuItems:(NSArray *)items {
self.flowLayout = [[CNPGridMenuFlowLayout alloc] init];
self = [super initWithCollectionViewLayout:self.flowLayout];
if (self) {
_blurEffectStyle = UIBlurEffectStyleDark;
_blurEffectStyle = CNPBlurEffectStyleDark;
_buttons = [NSMutableArray new];
_menuItems = items;
}
Expand All @@ -81,13 +81,25 @@ - (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

if (CNP_IS_IOS8) {
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:self.blurEffectStyle];
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:(UIBlurEffectStyle)self.blurEffectStyle];
self.blurView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
self.collectionView.backgroundView = self.blurView;
}
else {
UIImageView *backgroundBlurImage = ((UIImageView *)self.collectionView.backgroundView);
backgroundBlurImage.image = [backgroundBlurImage.image applyDarkEffect];
switch (self.blurEffectStyle) {
case CNPBlurEffectStyleDark:
backgroundBlurImage.image = [backgroundBlurImage.image applyDarkEffect];
break;
case CNPBlurEffectStyleExtraLight:
backgroundBlurImage.image = [backgroundBlurImage.image applyExtraLightEffect];
break;
case CNPBlurEffectStyleLight:
backgroundBlurImage.image = [backgroundBlurImage.image applyLightEffect];
break;
default:
break;
}
}

self.backgroundTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapOnBackgroundView:)];
Expand All @@ -97,7 +109,7 @@ - (void)viewWillAppear:(BOOL)animated {
}

- (UIStatusBarStyle)preferredStatusBarStyle {
return self.blurEffectStyle == UIBlurEffectStyleDark ? UIStatusBarStyleLightContent : UIStatusBarStyleDefault;
return self.blurEffectStyle == CNPBlurEffectStyleDark ? UIStatusBarStyleLightContent : UIStatusBarStyleDefault;
}

#pragma mark - UICollectionView Delegate & DataSource
Expand Down Expand Up @@ -145,7 +157,7 @@ @implementation CNPGridMenuCell

- (void)setupCell {
if (CNP_IS_IOS8) {
UIVisualEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:[UIBlurEffect effectWithStyle:self.blurEffectStyle]];
UIVisualEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:[UIBlurEffect effectWithStyle:(UIBlurEffectStyle)self.blurEffectStyle]];
self.vibrancyView = [[UIVisualEffectView alloc] initWithEffect:vibrancyEffect];
}
else {
Expand All @@ -156,7 +168,7 @@ - (void)setupCell {
self.circleButton = [[UIButton alloc] initWithFrame:CGRectZero];
[self.circleButton setBackgroundColor:[UIColor clearColor]];
self.circleButton.layer.borderWidth = 1.0f;
self.circleButton.layer.borderColor = [UIColor whiteColor].CGColor;
self.circleButton.layer.borderColor = self.blurEffectStyle == CNPBlurEffectStyleDark?[UIColor whiteColor].CGColor:[UIColor darkGrayColor].CGColor;
[self.circleButton addTarget:self action:@selector(buttonTouchDown:) forControlEvents:UIControlEventTouchDown];
[self.circleButton addTarget:self action:@selector(buttonTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
[self.circleButton addTarget:self action:@selector(buttonTouchUpOutside:) forControlEvents:UIControlEventTouchUpOutside];
Expand All @@ -168,7 +180,7 @@ - (void)setupCell {
}

self.iconView = [[UIImageView alloc] initWithFrame:CGRectZero];
self.iconView.tintColor = [UIColor whiteColor];
self.iconView.tintColor = self.blurEffectStyle == CNPBlurEffectStyleDark?[UIColor whiteColor]:[UIColor darkGrayColor];
[self.iconView setContentMode:UIViewContentModeScaleAspectFit];
if (CNP_IS_IOS8) {
[((UIVisualEffectView *)self.vibrancyView).contentView addSubview:self.iconView];
Expand All @@ -179,7 +191,7 @@ - (void)setupCell {

self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
[self.titleLabel setFont:[UIFont systemFontOfSize:14]];
[self.titleLabel setTextColor:[UIColor whiteColor]];
[self.titleLabel setTextColor:self.blurEffectStyle == CNPBlurEffectStyleDark?[UIColor whiteColor]:[UIColor darkGrayColor]];
[self.titleLabel setNumberOfLines:2];
[self.titleLabel setTextAlignment:NSTextAlignmentCenter];
if (CNP_IS_IOS8) {
Expand All @@ -190,7 +202,7 @@ - (void)setupCell {
}
}

- (void)setBlurEffectStyle:(UIBlurEffectStyle)blurEffectStyle {
- (void)setBlurEffectStyle:(CNPBlurEffectStyle)blurEffectStyle {
_blurEffectStyle = blurEffectStyle;
if (self.vibrancyView == nil) {
[self setupCell];
Expand All @@ -208,13 +220,25 @@ - (void)layoutSubviews {
}

- (void)buttonTouchDown:(UIButton *)button {
self.iconView.tintColor = [UIColor blackColor];
button.backgroundColor = [UIColor whiteColor];
if (self.blurEffectStyle == CNPBlurEffectStyleDark) {
self.iconView.tintColor = [UIColor blackColor];
button.backgroundColor = [UIColor whiteColor];
}
else {
self.iconView.tintColor = [UIColor whiteColor];
button.backgroundColor = [UIColor darkGrayColor];
}
}

- (void)buttonTouchUpInside:(UIButton *)button {
self.iconView.tintColor = [UIColor whiteColor];
button.backgroundColor = [UIColor clearColor];
if (self.blurEffectStyle == CNPBlurEffectStyleDark) {
self.iconView.tintColor = [UIColor whiteColor];
button.backgroundColor = [UIColor clearColor];
}
else {
self.iconView.tintColor = [UIColor darkGrayColor];
button.backgroundColor = [UIColor clearColor];
}
if ([self.delegate respondsToSelector:@selector(didTapOnGridMenuItem:)]) {
[self.delegate didTapOnGridMenuItem:self.menuItem];
}
Expand All @@ -224,8 +248,14 @@ - (void)buttonTouchUpInside:(UIButton *)button {
}

- (void)buttonTouchUpOutside:(UIButton *)button {
self.iconView.tintColor = [UIColor whiteColor];
button.backgroundColor = [UIColor clearColor];
if (self.blurEffectStyle == CNPBlurEffectStyleDark) {
self.iconView.tintColor = [UIColor whiteColor];
button.backgroundColor = [UIColor clearColor];
}
else {
self.iconView.tintColor = [UIColor darkGrayColor];
button.backgroundColor = [UIColor clearColor];
}
}

@end
Expand Down

0 comments on commit e4ef5e8

Please sign in to comment.