YOUPAINIMInputAudioRecordIndicatorView.m 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // YOUPAINIMInputAudioRecordIndicatorView.m
  3. // NIMKit
  4. //
  5. // Created by chris.
  6. // Copyright (c) 2015年 NetEase. All rights reserved.
  7. //
  8. #import "YOUPAINIMInputAudioRecordIndicatorView.h"
  9. #import "UIImage+NIMKit.h"
  10. #define NIMKit_ViewWidth 160
  11. #define NIMKit_ViewHeight 110
  12. #define NIMKit_TimeFontSize 30
  13. #define NIMKit_TipFontSize 15
  14. @interface YOUPAINIMInputAudioRecordIndicatorView(){
  15. UIImageView *_backgrounView;
  16. UIImageView *_tipBackgroundView;
  17. }
  18. @property (nonatomic, strong) UILabel *timeLabel;
  19. @property (nonatomic, strong) UILabel *tipLabel;
  20. @end
  21. @implementation YOUPAINIMInputAudioRecordIndicatorView
  22. - (instancetype)init {
  23. self = [super init];
  24. if(self) {
  25. self.frame = CGRectMake(0, 0, 149, 100);
  26. self.layer.cornerRadius = 6;
  27. self.layer.masksToBounds = YES;
  28. _backgrounView = [[UIImageView alloc] initWithImage:[UIImage nim_imageInKit:@"icon_input_record_indicator"]];
  29. [self addSubview:_backgrounView];
  30. _tipBackgroundView = [[UIImageView alloc] initWithImage:[UIImage nim_imageInKit:@"icon_input_record_indicator_cancel"]];
  31. _tipBackgroundView.hidden = YES;
  32. _tipBackgroundView.frame = CGRectMake(0, NIMKit_ViewHeight - CGRectGetHeight(_tipBackgroundView.bounds), NIMKit_ViewWidth, CGRectGetHeight(_tipBackgroundView.bounds));
  33. [self addSubview:_tipBackgroundView];
  34. _timeLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  35. // _timeLabel.font = [UIFont boldSystemFontOfSize:14];
  36. _timeLabel.font = [UIFont boldSystemFontOfSize:NIMKit_TimeFontSize];
  37. _timeLabel.textColor = [UIColor whiteColor];
  38. _timeLabel.textAlignment = NSTextAlignmentCenter;
  39. _timeLabel.text = @"00:00";
  40. [self addSubview:_timeLabel];
  41. _tipLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  42. // _tipLabel.font = [UIFont systemFontOfSize:12];
  43. _tipLabel.font = [UIFont systemFontOfSize:NIMKit_TipFontSize];
  44. _tipLabel.textColor = [UIColor whiteColor];
  45. _tipLabel.textAlignment = NSTextAlignmentCenter;
  46. _tipLabel.text = @"手指上滑,取消发送";
  47. [self addSubview:_tipLabel];
  48. self.phase = AudioRecordPhaseEnd;
  49. }
  50. return self;
  51. }
  52. - (void)setRecordTime:(NSTimeInterval)recordTime {
  53. NSInteger minutes = (NSInteger)recordTime / 60;
  54. NSInteger seconds = (NSInteger)recordTime % 60;
  55. _timeLabel.text = [NSString stringWithFormat:@"%02zd:%02zd", minutes, seconds];
  56. }
  57. - (void)setPhase:(NIMAudioRecordPhase)phase {
  58. if(phase == AudioRecordPhaseStart) {
  59. [self setRecordTime:0];
  60. } else if(phase == AudioRecordPhaseCancelling) {
  61. _tipLabel.text = @"松开手指,取消发送";
  62. _tipBackgroundView.hidden = YES;
  63. // _tipLabel.textColor = HexColorFromRGB(0x79262C);
  64. // _timeLabel.textColor = HexColorFromRGB(0xD63641);
  65. } else {
  66. _tipLabel.text = @"手指上滑,取消发送";
  67. _tipBackgroundView.hidden = YES;
  68. // _tipLabel.textColor = HexColorFromRGB(0x9F9DA5);
  69. // _timeLabel.textColor = [UIColor whiteColor];
  70. }
  71. }
  72. - (void)layoutSubviews {
  73. CGSize size = [_timeLabel sizeThatFits:CGSizeMake(NIMKit_ViewWidth, MAXFLOAT)];
  74. _timeLabel.frame = CGRectMake(0, 23, 149, size.height);
  75. // _timeLabel.frame = CGRectMake(0, 66, NIMKit_ViewWidth, size.height);
  76. size = [_tipLabel sizeThatFits:CGSizeMake(NIMKit_ViewWidth, MAXFLOAT)];
  77. _tipLabel.frame = CGRectMake(0, 62, 149, size.height);
  78. }
  79. @end