新浪微博客户端(48)-添加删除按钮到表情键盘

Posted 夜行过客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了新浪微博客户端(48)-添加删除按钮到表情键盘相关的知识,希望对你有一定的参考价值。

 

DJEmotionPageView.m

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        UIButton *deleteBtn = [[UIButton alloc] init];
        [deleteBtn setImage:[UIImage imageNamed:@"compose_emotion_delete"] forState:UIControlStateNormal];
        [deleteBtn setImage:[UIImage imageNamed:@"compose_emotion_delete_highlighted"] forState:UIControlStateHighlighted];
        [self addSubview:deleteBtn];
        self.deleteBtn = deleteBtn;
        
    }
    return self;
}

 

- (void)layoutSubviews {

    [super layoutSubviews];
    
    CGFloat emotionW = (self.width - 2 * DJEmotionPageViewPadding) / DJEmotionPageViewMaxCols;
    CGFloat emotionH = (self.height - DJEmotionPageViewPadding) / DJEmotionPageViewMaxRows;
    
    NSUInteger emotionsCount = self.emotions.count;
    for (int i = 0; i < emotionsCount; i++) {
        UIView *emotionView = self.subviews[i+1]; // 遍历应该从第1个按钮,不应该从第0个,因为第0个View是删除按钮
        emotionView.x = (i % DJEmotionPageViewMaxCols) * emotionW + DJEmotionPageViewPadding;
        emotionView.y = (i / DJEmotionPageViewMaxCols) * emotionH + DJEmotionPageViewPadding;
        emotionView.width = emotionW;
        emotionView.height = emotionH;
    }
    
    // 删除按钮
    CGFloat deleteBtnW = emotionW;
    CGFloat deleteBtnH = emotionH;
    CGFloat deleteBtnX = self.width - DJEmotionPageViewPadding - deleteBtnW;
    CGFloat deleteBtnY = self.height - deleteBtnH;
    self.deleteBtn.frame = CGRectMake(deleteBtnX, deleteBtnY, deleteBtnW, deleteBtnH);
    
}

 

最终效果:

 

以上是关于新浪微博客户端(48)-添加删除按钮到表情键盘的主要内容,如果未能解决你的问题,请参考以下文章

新浪微博客户端(42)-完善表情键盘的工具条

新浪微博客户端(46)-点击表情按钮弹出表情

新浪微博客户端(49)-删除输入的Emotion表情

新浪微博客户端(53)-记录用户最近点击表情

新浪微博客户端(45)-显示表情

新浪微博客户端(43)-切换表情控件