@@ -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 {
0 commit comments