JXRemindCell.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // JXRemindCell.m
  3. // shiku_im
  4. //
  5. // Created by Apple on 16/10/11.
  6. // Copyright © 2016年 Reese. All rights reserved.
  7. //
  8. #import "JXRemindCell.h"
  9. #import "JXRoomRemind.h"
  10. @implementation JXRemindCell
  11. - (void)awakeFromNib {
  12. [super awakeFromNib];
  13. // Initialization code
  14. }
  15. -(void)creatUI{
  16. _baseView = [[UIView alloc] initWithFrame:CGRectMake(40, 10, JX_SCREEN_WIDTH-80, 0)];
  17. _baseView.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.5];
  18. _baseView.layer.cornerRadius = 3.f;
  19. _baseView.layer.masksToBounds = YES;
  20. [self.contentView addSubview:_baseView];
  21. _messageRemind=[[UILabel alloc] initWithFrame:CGRectMake(0, 10, 200, 20)];
  22. _messageRemind.userInteractionEnabled = NO;
  23. // _messageRemind.lineBreakMode = NSLineBreakByCharWrapping;
  24. _messageRemind.textAlignment = NSTextAlignmentCenter;
  25. _messageRemind.lineBreakMode = NSLineBreakByTruncatingTail;
  26. _messageRemind.backgroundColor = [UIColor clearColor];
  27. // _messageRemind.layer.borderWidth = 1;
  28. // _messageRemind.layer.borderColor = [[UIColor whiteColor] colorWithAlphaComponent:0.5].CGColor;
  29. _messageRemind.textColor = HEXCOLOR(0x999999);
  30. _messageRemind.font = g_factory.font13;
  31. _messageRemind.numberOfLines = 6.f;
  32. [_baseView addSubview:_messageRemind];
  33. self.confirmBtn = [[UIButton alloc] init];
  34. self.confirmBtn.backgroundColor = [UIColor clearColor];
  35. [self.confirmBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
  36. [_baseView addSubview:self.confirmBtn];
  37. }
  38. - (void)btnAction:(UIButton *)btn {
  39. [g_notify postNotificationName:kCellRemindNotifaction object:self.msg];
  40. }
  41. -(void)setCellData{
  42. if ([self.msg.type intValue] == kWCMessageTypeSuperDelete) {
  43. }
  44. if([self.msg.type intValue] == kWCMessageTypeRemind){
  45. // _messageRemind.textColor = [UIColor whiteColor];
  46. // _messageRemind.backgroundColor = HEXCOLOR(0xB5B5B5);
  47. NSString *content;
  48. if (self.msg.isShowTime) {
  49. NSString* t = [TimeUtil formatDate:self.msg.timeSend format:@"MM-dd HH:mm"];
  50. content = [NSString stringWithFormat:@" %@ (%@) ",self.msg.content,t];
  51. t = nil;
  52. }else {
  53. content = [NSString stringWithFormat:@" %@ ",self.msg.content];
  54. }
  55. NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithString:content];
  56. NSRange range = [content rangeOfString:Localized(@"JX_ToConfirm")];
  57. NSRange range1 = [content rangeOfString:Localized(@"JX_VerifyConfirmed")];
  58. if (range.location == NSNotFound) {
  59. range = range1;
  60. }
  61. if (range.location != NSNotFound) {
  62. [att addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:range];
  63. self.msg.remindType = [NSNumber numberWithInt:kRoomRemind_NeedVerify];
  64. }
  65. NSRange range2 = [content rangeOfString:Localized(@"JX_ShikuRedPacket")];
  66. if (range.location == NSNotFound) {
  67. if (range2.location != NSNotFound) {
  68. range = range2;
  69. [att addAttribute:NSForegroundColorAttributeName value:HEXCOLOR(0xF58A2E) range:range2];
  70. self.msg.remindType = [NSNumber numberWithInt:kWCMessageTypeRedPacketReceive];
  71. }
  72. }
  73. _messageRemind.attributedText = att;
  74. CGSize size = [_messageRemind.text boundingRectWithSize:CGSizeMake(JX_SCREEN_WIDTH - 80-14, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:g_factory.font13} context:nil].size;
  75. CGSize allSize = [_messageRemind.text boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:g_factory.font13} context:nil].size;
  76. if (size.height > 80) {
  77. size.height = 80;
  78. }
  79. int w = size.width;
  80. if (allSize.width+14 > JX_SCREEN_WIDTH-80) {
  81. // 多行
  82. w = JX_SCREEN_WIDTH-80-14;
  83. _baseView.frame = CGRectMake((JX_SCREEN_WIDTH-w-14)/2, _baseView.frame.origin.y, w+14, size.height+10);
  84. _messageRemind.frame = CGRectMake(7, 5, w, size.height);
  85. }else {
  86. //单行
  87. _baseView.frame = CGRectMake((JX_SCREEN_WIDTH-w-14)/2, _baseView.frame.origin.y, w+14, size.height+10);
  88. _messageRemind.frame = CGRectMake(6, 5, w, size.height);
  89. }
  90. if (range.location != NSNotFound) {
  91. [att addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:range];
  92. NSString *str = [content substringToIndex:range.location];
  93. CGSize size = [str boundingRectWithSize:CGSizeMake(JX_SCREEN_WIDTH - 20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:g_factory.font13} context:nil].size;
  94. self.confirmBtn.frame = CGRectMake(size.width + _messageRemind.frame.origin.x, 0, 50, size.height + 5);
  95. }
  96. }
  97. }
  98. + (float)getChatCellHeight:(JXMessageObject *)msg {
  99. if ([msg.type intValue] == kWCMessageTypeSuperDelete) {
  100. return 0;
  101. }
  102. NSString *str = nil;
  103. if (msg.isShowTime) {
  104. NSString* t = [TimeUtil formatDate:msg.timeSend format:@"MM-dd HH:mm"];
  105. str = [NSString stringWithFormat:@" %@ (%@) ",msg.content,t];
  106. t = nil;
  107. }else {
  108. str = [NSString stringWithFormat:@" %@ ",msg.content];
  109. }
  110. CGSize size = [str boundingRectWithSize:CGSizeMake(JX_SCREEN_WIDTH - 80-14, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:g_factory.font13} context:nil].size;
  111. if (size.height > 80) {
  112. size.height = 80;
  113. }
  114. float n = size.height + 5 + 18;
  115. return n;
  116. }
  117. -(void)didTouch:(UIButton*)button{
  118. }
  119. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  120. [super setSelected:selected animated:animated];
  121. // Configure the view for the selected state
  122. }
  123. @end