zoukankan      html  css  js  c++  java
  • 新浪微博客户端(42)-完善表情键盘的工具条

    DJEmotionTabBar.m

    //
    //  DJEmotionTabBar.m
    //  微博
    //
    //  Created by 海月高 on 16/11/26.
    //  Copyright © 2016年 yongdaimi. All rights reserved.
    //
    
    #import "DJEmotionTabBar.h"
    #import "DJEmotionTabBarButton.h"
    
    @interface DJEmotionTabBar()
    
    @property (nonatomic,weak) UIButton *selectedBtn;
    
    @end
    
    @implementation DJEmotionTabBar
    
    
    - (instancetype)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
        
            // 添加选项btn
            [self setupBtnTitle:@"最近" type:DJEmotionTabBarButtonTypeRecent];
            DJEmotionTabBarButton *defaultBtn = [self setupBtnTitle:@"默认" type:DJEmotionTabBarButtonTypeDefault];
            [self setupBtnTitle:@"Emoji" type:DJEmotionTabBarButtonTypeEmoji];
            [self setupBtnTitle:@"浪小花" type:DJEmotionTabBarButtonTypeLxh];
            
            
            // 设置“默认”选项的btn为选中状态
            [self btnClick:defaultBtn];
            
        }
        return self;
    }
    
    
    
    - (DJEmotionTabBarButton *)setupBtnTitle:(NSString *)title type:(DJEmotionTabBarButtonType)buttonType{
    
        
        DJEmotionTabBarButton *btn = [[DJEmotionTabBarButton alloc] init];
        [btn setTitle:title forState:UIControlStateNormal];
        
        [btn setTitleColor:DJColor(140,140,140) forState:UIControlStateNormal];
        [btn setTitleColor:DJColor(86, 86, 86) forState:UIControlStateSelected];
        
        
        [btn setBackgroundImage:[UIImage imageNamed:@"compose_emotion_table_normal"] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"compose_emotion_table_selected"] forState:UIControlStateSelected];
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchDown];
    
        btn.titleLabel.font = [UIFont systemFontOfSize:13];
        
        [btn setTag:buttonType];
        
        [self addSubview:btn];
        
        return btn;
    
    }
    
    
    
    - (void)layoutSubviews {
    
        [super layoutSubviews];
        NSUInteger count =  self.subviews.count;
        CGFloat btnY = 0;
        CGFloat btnH = self.height;
        CGFloat btnW = self.width / count;
        for (int i = 0; i < count; i++) {
            UIButton *btn = self.subviews[i];
            btn.x = i * btnW;
            btn.y = btnY;
            btn.width = btnW;
            btn.height = btnH;
        }
        
    }
    
    
    
    - (void)btnClick:(DJEmotionTabBarButton *)btn {
    
        self.selectedBtn.selected = NO;
        btn.selected = YES;
        self.selectedBtn = btn;
        
        // 传递点击消息
        if ([self.delegate respondsToSelector:@selector(emotionTabBar:didSelectedButtonType:)]) {
            DJEmotionTabBarButtonType type =  (DJEmotionTabBarButtonType)btn.tag;
            [self.delegate emotionTabBar:self didSelectedButtonType:type];
        }
        
    }
    
    
    @end

    最终效果:

  • 相关阅读:
    python_函数_文件
    Day_2_Python_str_list_dict的使用
    Day_1_Python_循环和格式化
    influxdb2.0版本部署+自启
    格式化Java内存工具JOL输出
    卷心菜的屯币日记
    influxDB时序数据库2.0FLUX查询语法使用记录
    两种转换2021-01-01T00:00:00Z为2021-01-01 00:00:00时间格式的方式(UTC时间转为yyyy-MM-dd HH:mm:ss)
    ThreadLocal的用处
    CentOS7使用ISO镜像文件作为离线Yum源
  • 原文地址:https://www.cnblogs.com/yongdaimi/p/6107761.html
Copyright © 2011-2022 走看看