YOUPAINIMInputEmoticonTabView.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // YOUPAINIMInputEmoticonTabView.m
  3. // NIMKit
  4. //
  5. // Created by chris.
  6. // Copyright (c) 2015年 NetEase. All rights reserved.
  7. //
  8. #import "YOUPAINIMInputEmoticonTabView.h"
  9. #import "YOUPAINIMInputEmoticonManager.h"
  10. #import "UIView+NIM.h"
  11. #import "UIImage+NIMKit.h"
  12. #import "NIMGlobalMacro.h"
  13. const NSInteger NIMInputEmoticonTabViewHeight = 35;
  14. const NSInteger NIMInputEmoticonSendButtonWidth = 64;
  15. const CGFloat NIMInputLineBoarder = .5f;
  16. @interface YOUPAINIMInputEmoticonTabView()
  17. @property (nonatomic,strong) NSMutableArray * tabs;
  18. @property (nonatomic,strong) NSMutableArray * seps;
  19. @end
  20. #define sepColor NIMKit_UIColorFromRGB(0x8A8E93)
  21. @implementation YOUPAINIMInputEmoticonTabView
  22. - (instancetype)initWithFrame:(CGRect)frame{
  23. self = [super initWithFrame:CGRectMake(0, 0, frame.size.width, NIMInputEmoticonTabViewHeight)];
  24. if (self) {
  25. _tabs = [[NSMutableArray alloc] init];
  26. _seps = [[NSMutableArray alloc] init];
  27. _sendButton = [UIButton buttonWithType:UIButtonTypeCustom];
  28. [_sendButton setTitle:@"发送" forState:UIControlStateNormal];
  29. _sendButton.titleLabel.font = [UIFont systemFontOfSize:13.f];
  30. [_sendButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  31. // [_sendButton setBackgroundColor:NIMKit_UIColorFromRGB(0x0079FF)];
  32. _sendButton.nim_height = NIMInputEmoticonTabViewHeight;
  33. _sendButton.nim_width = NIMInputEmoticonSendButtonWidth;
  34. [self addSubview:_sendButton];
  35. [_sendButton setBackgroundImage:[LCTools ColorImage:CGSizeMake(NIMInputEmoticonSendButtonWidth, NIMInputEmoticonTabViewHeight) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:1] forState:UIControlStateNormal];
  36. // self.layer.borderColor = sepColor.CGColor;
  37. // self.layer.borderWidth = NIMInputLineBoarder;
  38. }
  39. return self;
  40. }
  41. - (void)youpaifloadCatalogs:(NSArray*)emoticonCatalogs
  42. {
  43. for (UIView *subView in [_tabs arrayByAddingObjectsFromArray:_seps]) {
  44. [subView removeFromSuperview];
  45. }
  46. [_tabs removeAllObjects];
  47. [_seps removeAllObjects];
  48. // for (NIMInputEmoticonCatalog * catelog in emoticonCatalogs) {
  49. // UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
  50. // [button setImage:[UIImage nim_fetchEmoticon:catelog.icon] forState:UIControlStateNormal];
  51. // [button setImage:[UIImage nim_fetchEmoticon:catelog.iconPressed] forState:UIControlStateHighlighted];
  52. // [button setImage:[UIImage nim_fetchEmoticon:catelog.iconPressed] forState:UIControlStateSelected];
  53. // [button addTarget:self action:@selector(onTouchTab:) forControlEvents:UIControlEventTouchUpInside];
  54. // [button sizeToFit];
  55. // [self addSubview:button];
  56. // [_tabs addObject:button];
  57. //
  58. // UIView *sep = [[UIView alloc] initWithFrame:CGRectMake(0, 0, NIMInputLineBoarder, NIMInputEmoticonTabViewHeight)];
  59. // sep.backgroundColor = sepColor;
  60. // [_seps addObject:sep];
  61. // [self addSubview:sep];
  62. // }
  63. }
  64. - (void)onTouchTab:(id)sender{
  65. NSInteger index = [self.tabs indexOfObject:sender];
  66. [self youpaifselectTabIndex:index];
  67. if ([self.delegate respondsToSelector:@selector(tabView:didSelectTabIndex:)]) {
  68. [self.delegate tabView:self didSelectTabIndex:index];
  69. }
  70. }
  71. - (void)youpaifselectTabIndex:(NSInteger)index{
  72. for (NSInteger i = 0; i < self.tabs.count ; i++) {
  73. UIButton *btn = self.tabs[i];
  74. btn.selected = i == index;
  75. }
  76. }
  77. - (void)layoutSubviews{
  78. [super layoutSubviews];
  79. CGFloat spacing = 10;
  80. CGFloat left = spacing;
  81. for (NSInteger index = 0; index < self.tabs.count ; index++) {
  82. UIButton *button = self.tabs[index];
  83. button.nim_left = left;
  84. button.nim_centerY = self.nim_height * .5f;
  85. UIView *sep = self.seps[index];
  86. sep.nim_left = (int)(button.nim_right + spacing);
  87. left = (int)(sep.nim_right + spacing);
  88. }
  89. _sendButton.nim_right = (int)self.nim_width;
  90. }
  91. @end