首页 > 代码库 > 新浪微博客户端(42)-完善表情键盘的工具条
新浪微博客户端(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
最终效果:
新浪微博客户端(42)-完善表情键盘的工具条
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。