twEmojiView.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // twEmojiView.m
  3. // TaiWanEight
  4. //
  5. // Created by Boom on 2017/11/23.
  6. // Copyright © 2017年 YangBiao. All rights reserved.
  7. //
  8. #import "twEmojiView.h"
  9. #import "emojiCell.h"
  10. @interface CollCellWhite : UICollectionViewCell
  11. @end
  12. @implementation CollCellWhite
  13. - (instancetype)init{
  14. self = [super init];
  15. if (self) {
  16. self.backgroundColor = [UIColor whiteColor];
  17. }
  18. return self;
  19. }
  20. @end
  21. @implementation twEmojiView{
  22. UICollectionView *collectionView;
  23. NSArray *emojiArray;
  24. UIPageControl *_pageControl;
  25. }
  26. -(instancetype)initWithFrame:(CGRect)frame{
  27. self = [super initWithFrame:frame];
  28. if (self) {
  29. self.backgroundColor = UIColor.whiteColor;
  30. emojiArray = @[@"[微笑]",@"[色]",@"[发呆]",@"[抽烟]",@"[抠鼻]",@"[哭]",@"[发怒]",@"[呲牙]",@"[睡]",@"[害羞]",@"[调皮]",@"[晕]",@"[衰]",@"[闭嘴]",@"[指点]",@"[关注]",@"[搞定]",@"[胜利]",@"[无奈]",@"[打脸]",@"msg_del",@"[大笑]",@"[哈欠]",@"[害怕]",@"[喜欢]",@"[困]",@"[疑问]",@"[伤心]",@"[鼓掌]",@"[得意]",@"[捂嘴]",@"[惊恐]",@"[思考]",@"[吐血]",@"[卖萌]",@"[嘘]",@"[生气]",@"[尴尬]",@"[笑哭]",@"[口罩]",@"[斜眼]",@"msg_del",@"[酷]",@"[脸红]",@"[大叫]",@"[眼泪]",@"[见钱]",@"[嘟]",@"[吓]",@"[开心]",@"[想哭]",@"[郁闷]",@"[互粉]",@"[赞]",@"[拜托]",@"[唇]",@"[粉]",@"[666]",@"[玫瑰]",@"[黄瓜]",@"[啤酒]",@"[无语]",@"msg_del",@"[纠结]",@"[吐舌]",@"[差评]",@"[飞吻]",@"[再见]",@"[拒绝]",@"[耳机]",@"[抱抱]",@"[嘴]",@"[露牙]",@"[黄狗]",@"[灰狗]",@"[蓝狗]",@"[狗]",@"[脸黑]",@"[吃瓜]",@"[绿帽]",@"[汗]",@"[摸头]",@"[阴险]",@"msg_del",@"[擦汗]",@"[瞪眼]",@"[疼]",@"[鬼脸]",@"[拇指]",@"[亲]",@"[大吐]",@"[高兴]",@"[敲打]",@"[加油]",@"[吐]",@"[握手]",@"[18禁]",@"[菜刀]",@"[威武]",@"[给力]",@"[爱心]",@"[心碎]",@"[便便]",@"[礼物]",@"msg_del",@"[生日]",@"[喝彩]",@"[雷]",@"345",@"345",@"345",@"345",@"345",@"345",@"345",@"345",@"345",@"345",@"345",@"345",@"345",@"345",@"345",@"345",@"345",@"msg_del"];
  31. [self creatUI];
  32. }
  33. return self;
  34. }
  35. - (void)setIsWhiteStyle:(BOOL)isWhiteStyle {
  36. _isWhiteStyle = isWhiteStyle;
  37. if (_isWhiteStyle) {
  38. self.backgroundColor = [UIColor whiteColor];
  39. collectionView.backgroundColor = [UIColor whiteColor];
  40. }
  41. }
  42. - (void)creatUI{
  43. LWLCollectionViewHorizontalLayout *layout =[[LWLCollectionViewHorizontalLayout alloc]init];
  44. layout.itemCountPerRow = 7;
  45. layout.rowCount = 3;
  46. layout.itemSize = CGSizeMake((_window_width-20)/7, (_window_width-20)/7);
  47. layout.minimumInteritemSpacing = 0;
  48. layout.minimumLineSpacing = 0;
  49. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  50. CGFloat collectinHeight = (_window_width-20)/7*3;
  51. collectionView =[[UICollectionView alloc] initWithFrame:CGRectMake(10,10, _window_width-20,collectinHeight) collectionViewLayout:layout];
  52. collectionView.backgroundColor = UIColor.whiteColor;
  53. collectionView.dataSource = self;
  54. collectionView.delegate = self;
  55. collectionView.pagingEnabled = YES;
  56. [collectionView registerClass:[CollCellWhite class] forCellWithReuseIdentifier:@"emojiWhite"];
  57. [collectionView registerNib:[UINib nibWithNibName:@"emojiCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"emojiCELL"];
  58. [self addSubview:collectionView];
  59. _pageControl = [[UIPageControl alloc] init];
  60. CGFloat pageSpace = (EmojiHeight - collectinHeight-20-20)/2;
  61. _pageControl.frame = CGRectMake(collectionView.width/2, collectionView.bottom+pageSpace, 20, 20);//指定位置大小
  62. //_pageControl.center.x = self.collectionView.center.x;
  63. _pageControl.pageIndicatorTintColor = [UIColor grayColor];// 设置非选中页的圆点颜色
  64. _pageControl.currentPageIndicatorTintColor = Pink_Cor; // 设置选中页的圆点颜色
  65. _pageControl.numberOfPages = (emojiArray.count%21==0)?(emojiArray.count/21):(emojiArray.count/21+1);
  66. _pageControl.currentPage = 0;
  67. [self addSubview:_pageControl];
  68. CGFloat sendSpace = (EmojiHeight - collectinHeight-20-30)/2;
  69. _sendEmojiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  70. _sendEmojiBtn.frame = CGRectMake(_window_width-70, collectionView.bottom+sendSpace, 60, 30);
  71. [_sendEmojiBtn setTitle:YZMsg(@"发送") forState:0];
  72. [_sendEmojiBtn setTitleColor:[UIColor whiteColor] forState:0];
  73. _sendEmojiBtn.titleLabel.font = SYS_Font(16);
  74. _sendEmojiBtn.backgroundColor = Pink_Cor;
  75. _sendEmojiBtn.layer.masksToBounds = YES;
  76. _sendEmojiBtn.layer.cornerRadius = 15;
  77. [_sendEmojiBtn addTarget:self action:@selector(clickSendBtn) forControlEvents:UIControlEventTouchUpInside];
  78. [self addSubview:_sendEmojiBtn];
  79. }
  80. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  81. int page = scrollView.contentOffset.x / collectionView.frame.size.width;
  82. // 设置页码
  83. _pageControl.currentPage = page;
  84. }
  85. -(void)clickSendBtn {
  86. [self.delegate clickSendEmojiBtn];
  87. }
  88. #pragma mark - UICollectionViewDataSource methods
  89. - (NSInteger)collectionView:(UICollectionView *)collectionView
  90. numberOfItemsInSection:(NSInteger)section {
  91. return emojiArray.count;
  92. }
  93. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
  94. cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  95. static NSString *identifierCell = @"emojiCELL";
  96. //UICollectionViewCell *cell = nil;
  97. if (indexPath.item >= emojiArray.count) {
  98. UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"emojiWhite"
  99. forIndexPath:indexPath];
  100. return cell;
  101. } else {
  102. emojiCell *cell = (emojiCell *)[collectionView dequeueReusableCellWithReuseIdentifier:identifierCell
  103. forIndexPath:indexPath];
  104. cell.emojiImgView.image = [UIImage imageNamed:emojiArray[indexPath.row]];
  105. NSString *imageName = emojiArray[indexPath.row];
  106. if ([lagType isEqual:EN]) {
  107. if ([imageName isEqual:@"[互粉]"] ||
  108. [imageName isEqual:@"[关注]"] ||
  109. [imageName isEqual:@"[粉]"] ||
  110. [imageName isEqual:@"[给力]"]) {
  111. imageName = [imageName stringByAppendingFormat:@"_en"];
  112. cell.emojiImgView.image = [UIImage imageNamed:imageName];
  113. }
  114. }
  115. return cell;
  116. }
  117. }
  118. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  119. if ([emojiArray[indexPath.row] isEqualToString:@"345"]) {
  120. return;
  121. }
  122. [self.delegate sendimage:emojiArray[indexPath.row]];
  123. }
  124. @end