From 7b02207537d35bfa1714bf8beafc921f717d100a Mon Sep 17 00:00:00 2001 From: 单军华 Date: Wed, 11 Jul 2018 10:47:42 +0800 Subject: [PATCH] 首次上传 --- screendisplay/Pods/HMEmoticon/表情键盘/Emoticon/HMEmoticonToolbar.m | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 110 insertions(+), 0 deletions(-) diff --git "a/screendisplay/Pods/HMEmoticon/\350\241\250\346\203\205\351\224\256\347\233\230/Emoticon/HMEmoticonToolbar.m" "b/screendisplay/Pods/HMEmoticon/\350\241\250\346\203\205\351\224\256\347\233\230/Emoticon/HMEmoticonToolbar.m" new file mode 100755 index 0000000..8e9fde8 --- /dev/null +++ "b/screendisplay/Pods/HMEmoticon/\350\241\250\346\203\205\351\224\256\347\233\230/Emoticon/HMEmoticonToolbar.m" @@ -0,0 +1,110 @@ +// +// HMEmoticonToolbar.m +// ������������ +// +// Created by ������ on 16/3/3. +// Copyright �� 2016��� itcast. All rights reserved. +// + +#import "HMEmoticonToolbar.h" +#import "UIImage+HMEmoticon.h" +#import "HMEmoticonManager.h" + +/// ������ tag ������������ +static NSInteger kEmoticonToolbarTagBaseValue = 1000; + +@implementation HMEmoticonToolbar { + UIButton *_selectedButton; +} + +#pragma mark - ������������ +- (instancetype)initWithFrame:(CGRect)frame { + self = [super initWithFrame:frame]; + if (self) { + [self prepareUI]; + } + return self; +} + +- (instancetype)initWithCoder:(NSCoder *)coder { + self = [super initWithCoder:coder]; + if (self) { + [self prepareUI]; + } + return self; +} + +- (void)layoutSubviews { + [super layoutSubviews]; + + // ������������������������ + CGRect rect = self.bounds; + CGFloat w = rect.size.width / self.subviews.count; + rect.size.width = w; + + int index = 0; + for (UIView *v in self.subviews) { + v.frame = CGRectOffset(rect, index++ * w, 0); + } +} + +#pragma mark - ������������ +- (void)selectSection:(NSInteger)section { + UIButton *button = [self viewWithTag:(section + kEmoticonToolbarTagBaseValue)]; + + [self selectedButtonWithButton:button]; +} + +#pragma mark - ������������ +/// ��������������������� +- (void)clickToolbarButton:(UIButton *)button { + if (button == _selectedButton) { + return; + } + [self selectedButtonWithButton:button]; + + [self.delegate emoticonToolbarDidSelectSection:button.tag - kEmoticonToolbarTagBaseValue]; +} + +/// ��������������������������������������� +- (void)selectedButtonWithButton:(UIButton *)button { + button.selected = !button.selected; + _selectedButton.selected = !_selectedButton.selected; + _selectedButton = button; +} + +#pragma mark - ������������ +- (void)prepareUI { + + NSArray *packages = [HMEmoticonManager sharedManager].packages; + + // ������������ + NSInteger index = 0; + for (HMEmoticonPackage *package in packages) { + [self addChildButton:package.groupName bgImageName:package.bgImageName type:index++]; + } +} + +- (void)addChildButton:(NSString *)title bgImageName:(NSString *)bgImageName type:(NSInteger)type { + UIButton *btn = [[UIButton alloc] init]; + + btn.tag = type + kEmoticonToolbarTagBaseValue; + + [btn setTitle:title forState:UIControlStateNormal]; + btn.titleLabel.font = [UIFont systemFontOfSize:14]; + + [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; + [btn setTitleColor:[UIColor grayColor] forState:UIControlStateSelected]; + + NSString *imageName = [NSString stringWithFormat:@"compose_emotion_table_%@_normal", bgImageName]; + NSString *imageNameSL = [NSString stringWithFormat:@"compose_emotion_table_%@_selected", bgImageName]; + + [btn setBackgroundImage:[[UIImage hm_imageNamed:imageName] hm_resizableImage] forState:UIControlStateNormal]; + [btn setBackgroundImage:[[UIImage hm_imageNamed:imageNameSL] hm_resizableImage] forState:UIControlStateSelected]; + + [btn addTarget:self action:@selector(clickToolbarButton:) forControlEvents:UIControlEventTouchUpInside]; + + [self addSubview:btn]; +} + +@end -- Gitblit v1.8.0