Skip to content

Commit 05687ed

Browse files
committed
0.0.03
Added comments to EMEmojiableBtnConfig; Full ui customization using EMEmojiableBtnConfig; Minor bug fixes; Updated readme;
2 parents bc3223a + 0360874 commit 05687ed

File tree

8 files changed

+199
-32
lines changed

8 files changed

+199
-32
lines changed

EMEmojiableBtn.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

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

1414
# This description is used to generate tags and improve search results.

Pod/Classes/EMEmojiableBtn.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212

1313
@protocol EMEmojiableBtnDelegate;
1414
@interface EMEmojiableBtn : UIButton
15-
@property (strong,nonatomic) NSArray<EMEmojiableOption *> *dataset;
15+
@property (strong,nonatomic) NSArray * _Nonnull dataset;
1616
@property (weak,readwrite) id <EMEmojiableBtnDelegate> delegate;
1717

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

2121
@protocol EMEmojiableBtnDelegate <NSObject>
2222
@optional
23-
- (void)EMEmojiableBtn:(EMEmojiableBtn*)button selectedOption:(NSUInteger)index;
24-
- (void)EMEmojiableBtnCanceledAction:(EMEmojiableBtn*)button;
25-
- (void)EMEmojiableBtnSingleTap:(EMEmojiableBtn*)button;
23+
- (void)EMEmojiableBtn:( EMEmojiableBtn* _Nonnull)button selectedOption:(NSUInteger)index;
24+
- (void)EMEmojiableBtnCanceledAction:(EMEmojiableBtn* _Nonnull)button;
25+
- (void)EMEmojiableBtnSingleTap:(EMEmojiableBtn* _Nonnull)button;
2626
@end

Pod/Classes/EMEmojiableBtn.m

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ @interface EMEmojiableBtn()
2222
@property (assign,nonatomic) int selectedItem;
2323
@end
2424

25-
@implementation EMEmojiableBtn
25+
@implementation EMEmojiableBtn{
26+
NSArray *_dataset;
27+
}
2628
@synthesize selectorBgView;
2729
@synthesize optionsView;
2830
@synthesize longPressGesture;
@@ -70,7 +72,6 @@ - (void)privateInit{
7072

7173
- (EMEmojiableBtnConfig*)config{
7274
if(_config == nil){
73-
NSLog(@"Init Config");
7475
return self.config = [[EMEmojiableBtnConfig alloc] init];
7576
}
7677
return _config;
@@ -81,9 +82,11 @@ - (void)activate{
8182
if(active){
8283
return;
8384
}
84-
if(self.dataset == nil){
85+
if(_dataset == nil){
86+
[NSException raise:@"Invalid _dataset value" format:@"_dataset can't be nil", _dataset];
8587
return;
8688
}
89+
8790
selectedItem = -1;
8891
active = YES;
8992

@@ -97,22 +100,22 @@ - (void)activate{
97100
}
98101

99102
selectorBgView = [[UIView alloc] initWithFrame:selectorViewFrame];
100-
selectorBgView.backgroundColor = [UIColor clearColor];
103+
selectorBgView.backgroundColor = self.config.backgroundColor;
101104
[self.superview addSubview:selectorBgView];
102105

103-
CGFloat buttonWidth = ((CGFloat)(self.dataset.count + 1) * self.config.spacing) +(self.config.size*(CGFloat)self.dataset.count);
106+
CGFloat buttonWidth = ((CGFloat)(_dataset.count + 1) * self.config.spacing) +(self.config.size*(CGFloat)_dataset.count);
104107
CGFloat buttonHeight = self.config.size+(2*self.config.spacing);
105108
CGSize sizeBtn = CGSizeMake(buttonWidth,buttonHeight);
106109

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

109112
optionsView = [[UIView alloc] initWithFrame:optionsViewFrame];
113+
optionsView.alpha = self.config.optionsViewInitialAlpha;
110114
optionsView.layer.cornerRadius = optionsView.frame.size.height/2.0;
111-
optionsView.backgroundColor = [UIColor whiteColor];
112-
optionsView.layer.shadowColor = [UIColor lightGrayColor].CGColor;
113-
optionsView.layer.shadowOffset = CGSizeMake(0.0, 0.0);
114-
optionsView.layer.shadowOpacity = 0.5;
115-
optionsView.alpha = 0.3;
115+
optionsView.backgroundColor = self.config.optionsViewBackgroundColor;
116+
optionsView.layer.shadowColor = self.config.optionsViewShadowColor.CGColor;
117+
optionsView.layer.shadowOffset = self.config.optionsViewShadowOffset;
118+
optionsView.layer.shadowOpacity = self.config.optionsViewShadowOpacity;
116119

117120
[selectorBgView addSubview:optionsView];
118121

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

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

145-
informationView = [[EMEmojiableInformationView alloc] initWithFrame:CGRectMake(0, origin.y, selectorViewFrame.size.width, self.frame.size.height)];
146-
informationView.backgroundColor = [UIColor whiteColor];
148+
informationView = [[EMEmojiableInformationView alloc] initWithFrame:CGRectMake(0, origin.y, selectorViewFrame.size.width, self.frame.size.height) withConfig:self.config];
149+
informationView.backgroundColor = self.config.informationViewBackgroundColor;
147150
[selectorBgView addSubview:informationView];
148151
}
149152

@@ -171,7 +174,7 @@ - (void)deActivate:(int)optionIndex{
171174
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);
172175
}
173176
} completion:^(BOOL finished) {
174-
if (finished && idx == (self.dataset.count/2)){
177+
if (finished && idx == (_dataset.count/2)){
175178
[UIView animateWithDuration:0.1 animations:^{
176179
CGRect optionsViewFrame = optionsView.frame;
177180
optionsViewFrame.origin.y = origin.y - (self.config.size+(2*self.config.spacing));
@@ -187,15 +190,15 @@ - (void)deActivate:(int)optionIndex{
187190
}
188191

189192
- (void)selectIndex:(int)index{
190-
if (index < 0 || index > self.dataset.count){
193+
if (index < 0 || index > _dataset.count){
191194
return;
192195
}
193196

194197
selectedItem = index;
195198
[informationView activateInfo:NO];
196199

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

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

254-
CGFloat t = optionsView.frame.size.width/(CGFloat)self.dataset.count;
257+
CGFloat t = optionsView.frame.size.width/(CGFloat)_dataset.count;
255258
if (point.y < (CGRectGetMinY(optionsView.frame) - 50) || point.y > (CGRectGetMaxY(informationView.frame) + 30)){
256259
[self looseFocus];
257260
}else{
258-
if (point.x-origin.x > 0 && point.x < CGRectGetMaxX(optionsView.frame)){
261+
if (point.x-origin.x > 0 && point.x < CGRectGetMaxX(optionsView.frame)-30){
259262
int selected = round((point.x-origin.x)/t);
260263
[self selectIndex:selected];
261264
}else{

Pod/Classes/EMEmojiableBtnConfig.h

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,89 @@
99
#import <Foundation/Foundation.h>
1010

1111
@interface EMEmojiableBtnConfig : NSObject
12+
/**
13+
Size of each option
14+
*/
1215
@property (assign,nonatomic) CGFloat size;
16+
17+
/**
18+
Size of option when it is hilighted
19+
*/
1320
@property (assign,nonatomic) CGFloat maxSize;
21+
22+
/**
23+
Size of options when one option is hilighted.
24+
When option is hilighted other options are smaller.
25+
*/
1426
@property (assign,nonatomic) CGFloat minSize;
27+
28+
/**
29+
Spacing between options
30+
*/
1531
@property (assign,nonatomic) CGFloat spacing;
32+
33+
/**
34+
Bottom space of option selector view to button and information view
35+
*/
1636
@property (assign,nonatomic) CGFloat s_options_selector;
37+
38+
/**
39+
Background color of screen when options selector is active after UILongPressGestureRecognizer
40+
*/
41+
@property (strong,nonatomic) UIColor* backgroundColor;
42+
43+
/**
44+
Initial opacity of options listing view
45+
*/
46+
@property (assign,nonatomic) CGFloat optionsViewInitialAlpha;
47+
48+
/**
49+
Background color of options listing view
50+
*/
51+
@property (strong,nonatomic) UIColor* optionsViewBackgroundColor;
52+
53+
/**
54+
Shadow color of options listing view
55+
*/
56+
@property (strong,nonatomic) UIColor* optionsViewShadowColor;
57+
58+
/**
59+
Opacity of options listing shadow
60+
*/
61+
@property (assign,nonatomic) CGFloat optionsViewShadowOpacity;
62+
63+
/**
64+
Offset of options listing shadow
65+
*/
66+
@property (assign,nonatomic) CGSize optionsViewShadowOffset;
67+
68+
/**
69+
Background color of information view
70+
*/
71+
@property (strong,nonatomic) UIColor* informationViewBackgroundColor;
72+
73+
/**
74+
Dots color of information view
75+
*/
76+
@property (strong,nonatomic) UIColor* informationViewDotsColor;
77+
78+
/**
79+
Border color of information view
80+
*/
81+
@property (strong,nonatomic) UIColor* informationViewBorderColor;
82+
83+
/**
84+
Font of information view
85+
*/
86+
@property (assign,nonatomic) UIFont* informationViewFont;
87+
88+
/**
89+
Text color of information view
90+
*/
91+
@property (strong,nonatomic) UIColor* informationViewTextColor;
92+
93+
/**
94+
Text for information view. Default : Release to cancel
95+
*/
96+
@property (strong,nonatomic) NSString* informationViewText;
1797
@end

Pod/Classes/EMEmojiableBtnConfig.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,24 @@ - (instancetype)init{
1717
self.minSize = 34;
1818
self.maxSize = 80;
1919
self.s_options_selector = 30;
20+
21+
self.backgroundColor = [UIColor clearColor];
22+
23+
self.optionsViewBackgroundColor = [UIColor whiteColor];
24+
self.optionsViewShadowColor = [UIColor lightGrayColor];
25+
self.optionsViewShadowOffset = CGSizeMake(0.0, 0.0);
26+
self.optionsViewShadowOpacity = .5;
27+
self.optionsViewInitialAlpha = .3;
28+
29+
self.informationViewBackgroundColor = [UIColor whiteColor];
30+
self.informationViewFont = [UIFont boldSystemFontOfSize:12.0];
31+
self.informationViewTextColor = [UIColor colorWithRed:0.57 green:0.59 blue:0.64 alpha:1];
32+
self.informationViewText = @"Release to cancel";
33+
34+
self.informationViewDotsColor = [UIColor colorWithRed:0.8 green:0.81 blue:0.82 alpha:1.0];
35+
self.informationViewBorderColor = [UIColor colorWithRed:0.8 green:0.81 blue:0.82 alpha:1.0];
2036
}
2137
return self;
2238
}
39+
2340
@end

Pod/Classes/EMEmojiableInformationView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
//
88

99
#import <UIKit/UIKit.h>
10+
#import "EMEmojiableBtnConfig.h";
1011

1112
@interface EMEmojiableInformationView : UIView
13+
- (instancetype)initWithFrame:(CGRect)frame withConfig:(EMEmojiableBtnConfig*)config;
1214
- (void)activateInfo:(BOOL)active;
1315
@end

Pod/Classes/EMEmojiableInformationView.m

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,19 @@
77
//
88

99
#import "EMEmojiableInformationView.h"
10+
#import "EMEmojiableBtnConfig.h"
1011

1112
@implementation EMEmojiableInformationView{
1213
UILabel *textInformation;
14+
EMEmojiableBtnConfig *_config;
15+
}
16+
17+
- (instancetype)initWithFrame:(CGRect)frame withConfig:(EMEmojiableBtnConfig*)config{
18+
self = [super initWithFrame:frame];
19+
if(self){
20+
_config = config;
21+
}
22+
return self;
1323
}
1424

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

2737
UIBezierPath *lineSuperior = [UIBezierPath bezierPath];
2838
[lineSuperior moveToPoint:CGPointMake(0,0)];
2939
[lineSuperior addLineToPoint:CGPointMake(rect.size.width,0)];
3040
lineSuperior.lineWidth = 1.0;
31-
[[UIColor colorWithRed:0.8 green:0.81 blue:0.82 alpha:1.0] setStroke];
41+
[_config.informationViewBorderColor setStroke];
3242
[lineSuperior stroke];
3343

3444
UIBezierPath *lineInferior = [UIBezierPath bezierPath];
3545
[lineInferior moveToPoint:CGPointMake(0,rect.size.height)];
3646
[lineInferior addLineToPoint:CGPointMake(rect.size.width,rect.size.height)];
3747
lineInferior.lineWidth = 1.0;
38-
[[UIColor colorWithRed:0.8 green:0.81 blue:0.82 alpha:1.0] setStroke];
48+
[_config.informationViewBorderColor setStroke];
3949
[lineInferior stroke];
4050

4151
textInformation = [[UILabel alloc] initWithFrame:CGRectMake(0,1,rect.size.width,rect.size.height-2)];
42-
textInformation.backgroundColor = [UIColor whiteColor];
43-
textInformation.textColor = [UIColor colorWithRed:0.57 green:0.59 blue:0.64 alpha:1];
44-
textInformation.text = @"Release to Cancel";
52+
textInformation.backgroundColor = self.backgroundColor;
53+
textInformation.textColor = _config.informationViewTextColor;
54+
textInformation.text = _config.informationViewText;
4555
textInformation.textAlignment = NSTextAlignmentCenter;
46-
textInformation.font = [UIFont boldSystemFontOfSize:12.0];
56+
textInformation.font = _config.informationViewFont;
4757
textInformation.alpha = 0;
4858

4959
[self addSubview:textInformation];

0 commit comments

Comments
 (0)