码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-12-02 01:12:21      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:oat   ons   span   style   set   class   let   view   type   

 

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)-添加删除按钮到表情键盘

标签:oat   ons   span   style   set   class   let   view   type   

原文地址:http://www.cnblogs.com/yongdaimi/p/6123752.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!