Skip to content

Commit

Permalink
0.0.03
Browse files Browse the repository at this point in the history
Added comments to EMEmojiableBtnConfig;
Full ui customization using EMEmojiableBtnConfig;
Minor bug fixes;
Updated readme;
  • Loading branch information
Eke committed Apr 3, 2016
2 parents bc3223a + 0360874 commit 05687ed
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 32 deletions.
2 changes: 1 addition & 1 deletion EMEmojiableBtn.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = "EMEmojiableBtn"
s.version = "0.0.2"
s.version = "0.0.3"
s.summary = "Option selector that works similar to Reactions by fb. Objective-c version"

# This description is used to generate tags and improve search results.
Expand Down
8 changes: 4 additions & 4 deletions Pod/Classes/EMEmojiableBtn.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

@protocol EMEmojiableBtnDelegate;
@interface EMEmojiableBtn : UIButton
@property (strong,nonatomic) NSArray<EMEmojiableOption *> *dataset;
@property (strong,nonatomic) NSArray * _Nonnull dataset;
@property (weak,readwrite) id <EMEmojiableBtnDelegate> delegate;

- (instancetype)initWithFrame:(CGRect)frame withConfig:(EMEmojiableBtnConfig*)conf;
@end

@protocol EMEmojiableBtnDelegate <NSObject>
@optional
- (void)EMEmojiableBtn:(EMEmojiableBtn*)button selectedOption:(NSUInteger)index;
- (void)EMEmojiableBtnCanceledAction:(EMEmojiableBtn*)button;
- (void)EMEmojiableBtnSingleTap:(EMEmojiableBtn*)button;
- (void)EMEmojiableBtn:( EMEmojiableBtn* _Nonnull)button selectedOption:(NSUInteger)index;
- (void)EMEmojiableBtnCanceledAction:(EMEmojiableBtn* _Nonnull)button;
- (void)EMEmojiableBtnSingleTap:(EMEmojiableBtn* _Nonnull)button;
@end
43 changes: 23 additions & 20 deletions Pod/Classes/EMEmojiableBtn.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ @interface EMEmojiableBtn()
@property (assign,nonatomic) int selectedItem;
@end

@implementation EMEmojiableBtn
@implementation EMEmojiableBtn{
NSArray *_dataset;
}
@synthesize selectorBgView;
@synthesize optionsView;
@synthesize longPressGesture;
Expand Down Expand Up @@ -70,7 +72,6 @@ - (void)privateInit{

- (EMEmojiableBtnConfig*)config{
if(_config == nil){
NSLog(@"Init Config");
return self.config = [[EMEmojiableBtnConfig alloc] init];
}
return _config;
Expand All @@ -81,9 +82,11 @@ - (void)activate{
if(active){
return;
}
if(self.dataset == nil){
if(_dataset == nil){
[NSException raise:@"Invalid _dataset value" format:@"_dataset can't be nil", _dataset];
return;
}

selectedItem = -1;
active = YES;

Expand All @@ -97,22 +100,22 @@ - (void)activate{
}

selectorBgView = [[UIView alloc] initWithFrame:selectorViewFrame];
selectorBgView.backgroundColor = [UIColor clearColor];
selectorBgView.backgroundColor = self.config.backgroundColor;
[self.superview addSubview:selectorBgView];

CGFloat buttonWidth = ((CGFloat)(self.dataset.count + 1) * self.config.spacing) +(self.config.size*(CGFloat)self.dataset.count);
CGFloat buttonWidth = ((CGFloat)(_dataset.count + 1) * self.config.spacing) +(self.config.size*(CGFloat)_dataset.count);
CGFloat buttonHeight = self.config.size+(2*self.config.spacing);
CGSize sizeBtn = CGSizeMake(buttonWidth,buttonHeight);

CGRect optionsViewFrame = CGRectMake(origin.x, origin.y - sizeBtn.height, sizeBtn.width, sizeBtn.height);

optionsView = [[UIView alloc] initWithFrame:optionsViewFrame];
optionsView.alpha = self.config.optionsViewInitialAlpha;
optionsView.layer.cornerRadius = optionsView.frame.size.height/2.0;
optionsView.backgroundColor = [UIColor whiteColor];
optionsView.layer.shadowColor = [UIColor lightGrayColor].CGColor;
optionsView.layer.shadowOffset = CGSizeMake(0.0, 0.0);
optionsView.layer.shadowOpacity = 0.5;
optionsView.alpha = 0.3;
optionsView.backgroundColor = self.config.optionsViewBackgroundColor;
optionsView.layer.shadowColor = self.config.optionsViewShadowColor.CGColor;
optionsView.layer.shadowOffset = self.config.optionsViewShadowOffset;
optionsView.layer.shadowOpacity = self.config.optionsViewShadowOpacity;

[selectorBgView addSubview:optionsView];

Expand All @@ -123,8 +126,8 @@ - (void)activate{
self.optionsView.alpha = 1.0;
}];

for (int i = 0; i<self.dataset.count;++i){
EMEmojiableOption *option = [self.dataset objectAtIndex:i];
for (int i = 0; i<_dataset.count;++i){
EMEmojiableOption *option = [_dataset objectAtIndex:i];
UIImageView *optionImageView = [[UIImageView alloc] initWithFrame:CGRectMake(((CGFloat)(i+1)*self.config.spacing)+(self.config.size*(CGFloat)i),sizeBtn.height*1.2,10,10)];
optionImageView.image = [UIImage imageNamed:option.imageName];
optionImageView.alpha = 0.6;
Expand All @@ -142,8 +145,8 @@ - (void)activate{
} completion:nil];
}

informationView = [[EMEmojiableInformationView alloc] initWithFrame:CGRectMake(0, origin.y, selectorViewFrame.size.width, self.frame.size.height)];
informationView.backgroundColor = [UIColor whiteColor];
informationView = [[EMEmojiableInformationView alloc] initWithFrame:CGRectMake(0, origin.y, selectorViewFrame.size.width, self.frame.size.height) withConfig:self.config];
informationView.backgroundColor = self.config.informationViewBackgroundColor;
[selectorBgView addSubview:informationView];
}

Expand Down Expand Up @@ -171,7 +174,7 @@ - (void)deActivate:(int)optionIndex{
option.center = CGPointMake(((CGFloat)idx+1.0*self.config.spacing)+(self.config.size*(CGFloat)idx)+self.config.size/2.0, self.optionsView.frame.size.height+self.config.size/2.0);
}
} completion:^(BOOL finished) {
if (finished && idx == (self.dataset.count/2)){
if (finished && idx == (_dataset.count/2)){
[UIView animateWithDuration:0.1 animations:^{
CGRect optionsViewFrame = optionsView.frame;
optionsViewFrame.origin.y = origin.y - (self.config.size+(2*self.config.spacing));
Expand All @@ -187,15 +190,15 @@ - (void)deActivate:(int)optionIndex{
}

- (void)selectIndex:(int)index{
if (index < 0 || index > self.dataset.count){
if (index < 0 || index > _dataset.count){
return;
}

selectedItem = index;
[informationView activateInfo:NO];

[UIView animateWithDuration:0.3 animations:^{
CGFloat buttonWidth = (((CGFloat)self.dataset.count-1*self.config.spacing)+(self.config.minSize*(CGFloat)self.dataset.count-1)+self.config.maxSize);
CGFloat buttonWidth = (((CGFloat)_dataset.count-1*self.config.spacing)+(self.config.minSize*(CGFloat)_dataset.count-1)+self.config.maxSize);
CGFloat buttonHeight = self.config.minSize+(2*self.config.spacing);
CGSize sizeBtn = CGSizeMake(buttonWidth,buttonHeight);

Expand Down Expand Up @@ -226,7 +229,7 @@ - (void)looseFocus{
selectedItem = -1;
[informationView activateInfo:YES];
[UIView animateWithDuration:0.3 animations:^{
CGFloat buttonWidth = (((CGFloat)self.dataset.count+1*self.config.spacing)+(self.config.size*(CGFloat)self.dataset.count));
CGFloat buttonWidth = (((CGFloat)_dataset.count+1*self.config.spacing)+(self.config.size*(CGFloat)_dataset.count));
CGFloat buttonHeight = self.config.size+(2.0*self.config.spacing);
CGSize sizeBtn = CGSizeMake(buttonWidth,buttonHeight);
optionsView.frame = optionsViewOriginalRect;
Expand All @@ -251,11 +254,11 @@ - (void)longTap:(UIGestureRecognizer*)gesture{
} else if (gesture.state == UIGestureRecognizerStateChanged){
CGPoint point = [gesture locationInView:selectorBgView];

CGFloat t = optionsView.frame.size.width/(CGFloat)self.dataset.count;
CGFloat t = optionsView.frame.size.width/(CGFloat)_dataset.count;
if (point.y < (CGRectGetMinY(optionsView.frame) - 50) || point.y > (CGRectGetMaxY(informationView.frame) + 30)){
[self looseFocus];
}else{
if (point.x-origin.x > 0 && point.x < CGRectGetMaxX(optionsView.frame)){
if (point.x-origin.x > 0 && point.x < CGRectGetMaxX(optionsView.frame)-30){
int selected = round((point.x-origin.x)/t);
[self selectIndex:selected];
}else{
Expand Down
80 changes: 80 additions & 0 deletions Pod/Classes/EMEmojiableBtnConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,89 @@
#import <Foundation/Foundation.h>

@interface EMEmojiableBtnConfig : NSObject
/**
Size of each option
*/
@property (assign,nonatomic) CGFloat size;

/**
Size of option when it is hilighted
*/
@property (assign,nonatomic) CGFloat maxSize;

/**
Size of options when one option is hilighted.
When option is hilighted other options are smaller.
*/
@property (assign,nonatomic) CGFloat minSize;

/**
Spacing between options
*/
@property (assign,nonatomic) CGFloat spacing;

/**
Bottom space of option selector view to button and information view
*/
@property (assign,nonatomic) CGFloat s_options_selector;

/**
Background color of screen when options selector is active after UILongPressGestureRecognizer
*/
@property (strong,nonatomic) UIColor* backgroundColor;

/**
Initial opacity of options listing view
*/
@property (assign,nonatomic) CGFloat optionsViewInitialAlpha;

/**
Background color of options listing view
*/
@property (strong,nonatomic) UIColor* optionsViewBackgroundColor;

/**
Shadow color of options listing view
*/
@property (strong,nonatomic) UIColor* optionsViewShadowColor;

/**
Opacity of options listing shadow
*/
@property (assign,nonatomic) CGFloat optionsViewShadowOpacity;

/**
Offset of options listing shadow
*/
@property (assign,nonatomic) CGSize optionsViewShadowOffset;

/**
Background color of information view
*/
@property (strong,nonatomic) UIColor* informationViewBackgroundColor;

/**
Dots color of information view
*/
@property (strong,nonatomic) UIColor* informationViewDotsColor;

/**
Border color of information view
*/
@property (strong,nonatomic) UIColor* informationViewBorderColor;

/**
Font of information view
*/
@property (assign,nonatomic) UIFont* informationViewFont;

/**
Text color of information view
*/
@property (strong,nonatomic) UIColor* informationViewTextColor;

/**
Text for information view. Default : Release to cancel
*/
@property (strong,nonatomic) NSString* informationViewText;
@end
17 changes: 17 additions & 0 deletions Pod/Classes/EMEmojiableBtnConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,24 @@ - (instancetype)init{
self.minSize = 34;
self.maxSize = 80;
self.s_options_selector = 30;

self.backgroundColor = [UIColor clearColor];

self.optionsViewBackgroundColor = [UIColor whiteColor];
self.optionsViewShadowColor = [UIColor lightGrayColor];
self.optionsViewShadowOffset = CGSizeMake(0.0, 0.0);
self.optionsViewShadowOpacity = .5;
self.optionsViewInitialAlpha = .3;

self.informationViewBackgroundColor = [UIColor whiteColor];
self.informationViewFont = [UIFont boldSystemFontOfSize:12.0];
self.informationViewTextColor = [UIColor colorWithRed:0.57 green:0.59 blue:0.64 alpha:1];
self.informationViewText = @"Release to cancel";

self.informationViewDotsColor = [UIColor colorWithRed:0.8 green:0.81 blue:0.82 alpha:1.0];
self.informationViewBorderColor = [UIColor colorWithRed:0.8 green:0.81 blue:0.82 alpha:1.0];
}
return self;
}

@end
2 changes: 2 additions & 0 deletions Pod/Classes/EMEmojiableInformationView.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
//

#import <UIKit/UIKit.h>
#import "EMEmojiableBtnConfig.h";

@interface EMEmojiableInformationView : UIView
- (instancetype)initWithFrame:(CGRect)frame withConfig:(EMEmojiableBtnConfig*)config;
- (void)activateInfo:(BOOL)active;
@end
24 changes: 17 additions & 7 deletions Pod/Classes/EMEmojiableInformationView.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@
//

#import "EMEmojiableInformationView.h"
#import "EMEmojiableBtnConfig.h"

@implementation EMEmojiableInformationView{
UILabel *textInformation;
EMEmojiableBtnConfig *_config;
}

- (instancetype)initWithFrame:(CGRect)frame withConfig:(EMEmojiableBtnConfig*)config{
self = [super initWithFrame:frame];
if(self){
_config = config;
}
return self;
}

- (void)drawRect:(CGRect)rect {
Expand All @@ -21,29 +31,29 @@ - (void)drawRect:(CGRect)rect {
CGFloat dashes [] = {dots.lineWidth * 0, 37};
NSInteger count = sizeof(dashes)/sizeof(dashes[0]);
[dots setLineDash:dashes count:count phase:0];
[[UIColor colorWithRed:0.8 green:0.81 blue:0.82 alpha:1.0] setStroke];
[_config.informationViewDotsColor setStroke];
[dots stroke];

UIBezierPath *lineSuperior = [UIBezierPath bezierPath];
[lineSuperior moveToPoint:CGPointMake(0,0)];
[lineSuperior addLineToPoint:CGPointMake(rect.size.width,0)];
lineSuperior.lineWidth = 1.0;
[[UIColor colorWithRed:0.8 green:0.81 blue:0.82 alpha:1.0] setStroke];
[_config.informationViewBorderColor setStroke];
[lineSuperior stroke];

UIBezierPath *lineInferior = [UIBezierPath bezierPath];
[lineInferior moveToPoint:CGPointMake(0,rect.size.height)];
[lineInferior addLineToPoint:CGPointMake(rect.size.width,rect.size.height)];
lineInferior.lineWidth = 1.0;
[[UIColor colorWithRed:0.8 green:0.81 blue:0.82 alpha:1.0] setStroke];
[_config.informationViewBorderColor setStroke];
[lineInferior stroke];

textInformation = [[UILabel alloc] initWithFrame:CGRectMake(0,1,rect.size.width,rect.size.height-2)];
textInformation.backgroundColor = [UIColor whiteColor];
textInformation.textColor = [UIColor colorWithRed:0.57 green:0.59 blue:0.64 alpha:1];
textInformation.text = @"Release to Cancel";
textInformation.backgroundColor = self.backgroundColor;
textInformation.textColor = _config.informationViewTextColor;
textInformation.text = _config.informationViewText;
textInformation.textAlignment = NSTextAlignmentCenter;
textInformation.font = [UIFont boldSystemFontOfSize:12.0];
textInformation.font = _config.informationViewFont;
textInformation.alpha = 0;

[self addSubview:textInformation];
Expand Down
Loading

0 comments on commit 05687ed

Please sign in to comment.