Add delete button
This commit is contained in:
parent
065dfb5954
commit
70fe2a76ff
|
|
@ -40,4 +40,11 @@
|
|||
self.textView.text = [self.textView.text stringByAppendingString:emoji];
|
||||
}
|
||||
|
||||
-(void)emojiView:(ISEmojiView *)emojiView didPressDeleteButton:(UIButton *)deletebutton{
|
||||
if (self.textView.text.length > 0) {
|
||||
NSRange lastRange = [self.textView.text rangeOfComposedCharacterSequenceAtIndex:self.textView.text.length-1];
|
||||
self.textView.text = [self.textView.text substringToIndex:lastRange.location];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -19,5 +19,10 @@
|
|||
@protocol ISEmojiViewDelegate <NSObject>
|
||||
|
||||
-(void)emojiView:(ISEmojiView *)emojiView didSelectEmoji:(NSString *)emoji;
|
||||
-(void)emojiView:(ISEmojiView *)emojiView didPressDeleteButton:(UIButton *)deletebutton;
|
||||
|
||||
@end
|
||||
|
||||
@interface ISDeleteButton : UIButton
|
||||
|
||||
@end
|
||||
|
|
@ -31,8 +31,8 @@ static const CGFloat EmojiFontSize = 32;
|
|||
self.emojis = [NSArray arrayWithContentsOfFile:plistPath];
|
||||
|
||||
//
|
||||
NSInteger rowNum = (CGRectGetWidth(frame) / EmojiWidth);
|
||||
NSInteger colNum = (CGRectGetHeight(frame) / EmojiHeight);
|
||||
NSInteger rowNum = (CGRectGetHeight(frame) / EmojiHeight);
|
||||
NSInteger colNum = (CGRectGetWidth(frame) / EmojiWidth);
|
||||
NSInteger numOfPage = ceil((float)[self.emojis count] / (float)(rowNum * colNum));
|
||||
|
||||
// init scrollview
|
||||
|
|
@ -51,9 +51,36 @@ static const CGFloat EmojiFontSize = 32;
|
|||
NSInteger column = 0;
|
||||
NSInteger page = 0;
|
||||
|
||||
for (int i = 0; i < [self.emojis count]; i++) {
|
||||
NSInteger emojiPointer = 0;
|
||||
for (int i = 0; i < [self.emojis count] + numOfPage - 1; i++) {
|
||||
|
||||
NSString *emoji = self.emojis[i];
|
||||
// Pagination
|
||||
if (i % (rowNum * colNum) == 0) {
|
||||
page ++; // Increase the number of pages
|
||||
row = 0; // the number of lines is 0
|
||||
column = 0; // the number of columns is 0
|
||||
}else if (i % colNum == 0) {
|
||||
// NewLine
|
||||
row += 1; // Increase the number of lines
|
||||
column = 0; // The number of columns is 0
|
||||
}
|
||||
|
||||
CGRect currentRect = CGRectMake(((page-1) * frame.size.width) + (column * EmojiWidth),
|
||||
row * EmojiHeight,
|
||||
EmojiWidth,
|
||||
EmojiHeight);
|
||||
|
||||
if (row == (rowNum - 1) && column == (colNum - 1)) {
|
||||
// last position of page, add delete button
|
||||
|
||||
ISDeleteButton *deleteButton = [ISDeleteButton buttonWithType:UIButtonTypeCustom];
|
||||
[deleteButton addTarget:self action:@selector(deleteButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
|
||||
deleteButton.frame = currentRect;
|
||||
deleteButton.tintColor = [UIColor blackColor];
|
||||
[self.scrollView addSubview:deleteButton];
|
||||
|
||||
}else{
|
||||
NSString *emoji = self.emojis[emojiPointer++];
|
||||
|
||||
// init Emoji Button
|
||||
UIButton *emojiButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
|
|
@ -61,24 +88,11 @@ static const CGFloat EmojiFontSize = 32;
|
|||
[emojiButton setTitle:emoji forState:UIControlStateNormal];
|
||||
[emojiButton addTarget:self action:@selector(emojiButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
// Pagination
|
||||
if (i % (rowNum * colNum) == 0) {
|
||||
page ++; // Increase the number of pages
|
||||
row = 0; // the number of lines is 0
|
||||
column = 0; // the number of columns is 0
|
||||
}else if (i % rowNum == 0) {
|
||||
// NewLine
|
||||
row += 1; // Increase the number of lines
|
||||
column = 0; // The number of columns is 0
|
||||
emojiButton.frame = currentRect;
|
||||
[self.scrollView addSubview:emojiButton];
|
||||
}
|
||||
|
||||
emojiButton.frame = CGRectMake(((page-1) * frame.size.width) + (column * EmojiWidth),
|
||||
row * EmojiHeight,
|
||||
EmojiWidth,
|
||||
EmojiHeight);
|
||||
column++;
|
||||
|
||||
[self.scrollView addSubview:emojiButton];
|
||||
}
|
||||
|
||||
// add PageControl
|
||||
|
|
@ -94,6 +108,8 @@ static const CGFloat EmojiFontSize = 32;
|
|||
pageControlSize.height);
|
||||
[self.pageControl addTarget:self action:@selector(pageControlTouched:) forControlEvents:UIControlEventValueChanged];
|
||||
[self addSubview:self.pageControl];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
|
@ -128,4 +144,49 @@ static const CGFloat EmojiFontSize = 32;
|
|||
}
|
||||
}
|
||||
|
||||
- (void)deleteButtonPressed:(UIButton *)button{
|
||||
// Add a simple scale animation
|
||||
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
|
||||
animation.toValue = @0.9;
|
||||
animation.duration = 0.1;
|
||||
animation.autoreverses = YES;
|
||||
[button.layer addAnimation:animation forKey:nil];
|
||||
|
||||
// Callback
|
||||
if ([self.delegate respondsToSelector:@selector(emojiView:didPressDeleteButton:)]) {
|
||||
[self.delegate emojiView:self didPressDeleteButton:button];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation ISDeleteButton
|
||||
|
||||
-(void)drawRect:(CGRect)rect{
|
||||
|
||||
// Rectangle Drawing
|
||||
UIBezierPath* rectanglePath = UIBezierPath.bezierPath;
|
||||
[rectanglePath moveToPoint: CGPointMake(5, 25.05)];
|
||||
[rectanglePath addLineToPoint: CGPointMake(20.16, 36)];
|
||||
[rectanglePath addLineToPoint: CGPointMake(45.5, 36)];
|
||||
[rectanglePath addLineToPoint: CGPointMake(45.5, 13.5)];
|
||||
[rectanglePath addLineToPoint: CGPointMake(20.16, 13.5)];
|
||||
[rectanglePath addLineToPoint: CGPointMake(5, 25.05)];
|
||||
[rectanglePath closePath];
|
||||
[self.tintColor setStroke];
|
||||
rectanglePath.lineWidth = 1;
|
||||
[rectanglePath stroke];
|
||||
|
||||
|
||||
// Bezier Drawing
|
||||
UIBezierPath* bezierPath = UIBezierPath.bezierPath;
|
||||
[bezierPath moveToPoint: CGPointMake(26.5, 20)];
|
||||
[bezierPath addLineToPoint: CGPointMake(36.5, 29.5)];
|
||||
[bezierPath moveToPoint: CGPointMake(36.5, 20)];
|
||||
[bezierPath addLineToPoint: CGPointMake(26.5, 29.5)];
|
||||
[self.tintColor setStroke];
|
||||
bezierPath.lineWidth = 1;
|
||||
[bezierPath stroke];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
Loading…
Reference in New Issue