JXCell.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. //
  2. // JXCell.m
  3. //
  4. // Created by flyeagleTang on 14-4-3.
  5. // Copyright (c) 2014年 Reese. All rights reserved.
  6. //
  7. #import "JXCell.h"
  8. #import "JXLabel.h"
  9. #import "JXImageView.h"
  10. #import "AppDelegate.h"
  11. @implementation JXCell
  12. @synthesize title,bottomTitle,headImage,bage,userId;
  13. @synthesize index,delegate,didTouch,lbTitle,lbBottomTitle,lbSubTitle;
  14. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  15. {
  16. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  17. if(self){
  18. //内容
  19. UIFont* f0 = [UIFont systemFontOfSize:12];
  20. //名称
  21. UIFont * f1 = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  22. //时间
  23. UIFont* timeFont = [UIFont systemFontOfSize:12];
  24. int n = 68;
  25. UIView* v = [[UIView alloc]initWithFrame:CGRectMake(0,0, JX_SCREEN_WIDTH, n)];
  26. v.backgroundColor = THE_LINE_COLOR;
  27. self.selectedBackgroundView = v;
  28. self.lineView = [[UIView alloc]initWithFrame:CGRectMake(SEPSRATOR_WIDTH,n-LINE_WH,JX_SCREEN_WIDTH,LINE_WH)];
  29. self.lineView.backgroundColor = kRGBColor(245, 245, 245);
  30. [self.contentView addSubview:self.lineView];
  31. _delBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 22, 20, 20)];
  32. [_delBtn setBackgroundImage:[UIImage imageNamed:@"delete"] forState:UIControlStateNormal];
  33. [_delBtn addTarget:self action:@selector(delBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  34. _delBtn.hidden = YES;
  35. [self.contentView addSubview:_delBtn];
  36. _headImageView = [[JXImageView alloc]init];
  37. _headImageView.userInteractionEnabled = NO;
  38. _headImageView.tag = index;
  39. _headImageView.delegate = self;
  40. _headImageView.didTouch = @selector(headImageDidTouch);
  41. _headImageView.frame = CGRectMake(15,10,40,40);
  42. _headImageView.layer.cornerRadius = 5;
  43. _headImageView.layer.masksToBounds = YES;
  44. _headImageView.layer.borderColor = [UIColor darkGrayColor].CGColor;
  45. [self.contentView addSubview:self.headImageView];
  46. [g_notify addObserver:self selector:@selector(headImageNotification:) name:kGroupHeadImageModifyNotifaction object:nil];
  47. //昵称Label
  48. JXLabel* lb;
  49. if (self.isShowNicknameRemarkNameTelphoneNumber) {
  50. lb = [[JXLabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_headImageView.frame)+15, 10, JX_SCREEN_WIDTH - 115 -CGRectGetMaxX(_headImageView.frame)-14, 18)];
  51. lb.textColor = HEXCOLOR(0x323232);
  52. lb.userInteractionEnabled = NO;
  53. lb.backgroundColor = [UIColor redColor];
  54. lb.font = f1;
  55. lb.tag = self.index;
  56. [self.contentView addSubview:lb];
  57. [lb setText:self.title];
  58. }else {
  59. lb = [[JXLabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_headImageView.frame)+15, 14, JX_SCREEN_WIDTH - 115 -CGRectGetMaxX(_headImageView.frame)-14, 18)];
  60. lb.textColor = HEXCOLOR(0x323232);
  61. lb.userInteractionEnabled = NO;
  62. lb.backgroundColor = [UIColor clearColor];
  63. lb.font = f1;
  64. lb.tag = self.index;
  65. [self.contentView addSubview:lb];
  66. [lb setText:self.title];
  67. }
  68. self.lbTitle = lb;
  69. _guanFLbTitle = [[JXLabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_headImageView.frame)+30+40, 16.5, 50, 18)];
  70. _guanFLbTitle.textColor =[UIColor whiteColor];
  71. _guanFLbTitle.userInteractionEnabled = NO;
  72. _guanFLbTitle.textAlignment=NSTextAlignmentCenter;
  73. _guanFLbTitle.backgroundColor = kRGBColor(72, 149, 236);
  74. _guanFLbTitle.layer.cornerRadius=5;
  75. _guanFLbTitle.layer.masksToBounds=YES;
  76. _guanFLbTitle.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
  77. [self.contentView addSubview:_guanFLbTitle];
  78. _guanFLbTitle.hidden=YES;
  79. [_guanFLbTitle setText:@"官方"];
  80. _positionLabel = [UIFactory createLabelWith:CGRectMake(CGRectGetMaxX(self.lbTitle.frame)+2, CGRectGetMinY(self.lbTitle.frame), 20, 20) text:@"" font:g_factory.font11 textColor:[UIColor whiteColor] backgroundColor:nil];
  81. _positionLabel.layer.backgroundColor = [UIColor orangeColor].CGColor;
  82. _positionLabel.layer.cornerRadius = 5;
  83. _positionLabel.textAlignment = NSTextAlignmentCenter;
  84. _positionLabel.hidden = YES;
  85. [self.contentView addSubview:_positionLabel];
  86. if (self.positionTitle.length > 0){
  87. self.positionTitle = self.positionTitle;
  88. }
  89. //聊天消息Label
  90. lb = [[JXLabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(_headImageView.frame)+15, 68-15-15, JX_SCREEN_WIDTH-86-50, 15)];
  91. lb.textColor = [UIColor lightGrayColor];
  92. lb.userInteractionEnabled = NO;
  93. lb.backgroundColor = [UIColor clearColor];
  94. lb.font = f0;
  95. [self.contentView addSubview:lb];
  96. [lb setText:self.subtitle];
  97. self.lbSubTitle = lb;
  98. //时间Label
  99. self.timeLabel = [[JXLabel alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 115-15, 40, 115, 12)];
  100. self.timeLabel.textColor = [UIColor lightGrayColor];
  101. self.timeLabel.userInteractionEnabled = NO;
  102. self.timeLabel.backgroundColor = [UIColor clearColor];
  103. self.timeLabel.textAlignment = NSTextAlignmentRight;
  104. self.timeLabel.font = timeFont;
  105. [self.contentView addSubview:self.timeLabel];
  106. [self.timeLabel setText:self.bottomTitle];
  107. self.lbBottomTitle = self.timeLabel;
  108. //快捷回复
  109. self.replayView = [[JXImageView alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH-45, 13, 45, 45)];
  110. self.replayView.hidden = YES;
  111. self.replayView.didTouch = @selector(didQuickReply);
  112. self.replayView.delegate = self;
  113. [self.contentView addSubview:self.replayView];
  114. _replayImgV = [[UIImageView alloc] initWithFrame:CGRectMake(15, 25, 15, 15)];
  115. _replayImgV.image = [UIImage imageNamed:@"msg_replay_icon"];
  116. //[self.replayView addSubview:_replayImgV];
  117. //免打扰图标
  118. self.notPushImageView = [[JXImageView alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH-15*3-10, CGRectGetMinY(lbSubTitle.frame), 15, 15)];
  119. self.notPushImageView.image = [UIImage imageNamed:@"msg_not_push"];
  120. self.notPushImageView.hidden = YES;
  121. [self.contentView addSubview:self.notPushImageView];
  122. self.tempChatL = [[UILabel alloc]initWithFrame:CGRectMake((JX_SCREEN_WIDTH)/2-60, 5, 100, 12)];
  123. self.tempChatL.textColor = [UIColor lightGrayColor];
  124. self.tempChatL.userInteractionEnabled = NO;
  125. self.tempChatL.text=@"临时会话";
  126. self.tempChatL.backgroundColor = [UIColor clearColor];
  127. self.tempChatL.textAlignment = NSTextAlignmentRight;
  128. self.tempChatL.font = [UIFont systemFontOfSize:15 weight:UIFontWeightRegular];
  129. [self.contentView addSubview:self.tempChatL];
  130. self.tempChatL.hidden=YES;
  131. //初级高级
  132. _chujiIMG = [[UIImageView alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH-84, 3, 72, 36)];
  133. //_chujiIMG.backgroundColor=[UIColor grayColor];
  134. //_chujiIMG.image = [UIImage imageNamed:@"msgChuji"];
  135. [self.contentView addSubview:_chujiIMG];
  136. _bageNumber = [[JXBadgeView alloc] initWithFrame:CGRectMake(55,3, 19, 19)];
  137. _bageNumber.delegate = delegate;
  138. _bageNumber.didDragout = self.didDragout;
  139. _bageNumber.userInteractionEnabled = YES;
  140. _bageNumber.lb.font = SYSFONT(12);
  141. [self.contentView addSubview:_bageNumber];
  142. //特别关心图标
  143. self.specialCareImageView = [[JXImageView alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH-25-15-10, 20, 15, 15)];
  144. self.specialCareImageView.image = [UIImage imageNamed:@"collection_me"];
  145. self.specialCareImageView.hidden = YES;
  146. [self.contentView addSubview:self.specialCareImageView];
  147. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didQuickReply)];
  148. [_bageNumber addGestureRecognizer:tap];
  149. self.bage = bage;
  150. // [self saveBadge:bage withTitle:self.title];
  151. }
  152. return self;
  153. }
  154. - (void)delBtnAction:(UIButton *)btn {
  155. if (self.delegate && [self.delegate respondsToSelector:self.didDelMsg]) {
  156. [self.delegate performSelectorOnMainThread:self.didDelMsg withObject:self waitUntilDone:YES];
  157. }
  158. }
  159. -(void)dealloc{
  160. // NSLog(@"JXCell.dealloc");
  161. // [self.bageDict removeAllObjects];
  162. // self.bageDict = nil;
  163. [g_notify removeObserver:self name:kGroupHeadImageModifyNotifaction object:nil];
  164. self.title = nil;
  165. self.subtitle = nil;
  166. self.bottomTitle = nil;
  167. self.headImage = nil;
  168. self.bage = nil;
  169. self.userId = nil;
  170. self.lbSubTitle = nil;
  171. self.guanFLbTitle=nil;
  172. self.lbTitle = nil;
  173. self.lbBottomTitle = nil;
  174. // self.bageDict = nil;
  175. // [_headImageView release];
  176. // [super dealloc];
  177. }
  178. - (void)setIsNotPush:(BOOL)isNotPush {
  179. _isNotPush = isNotPush;
  180. self.notPushImageView.hidden = !isNotPush;
  181. }
  182. - (void)setIsMsgVCCome:(BOOL)isMsgVCCome { // 只有JXMsgViewController显示回复按钮
  183. _isMsgVCCome = isMsgVCCome;
  184. self.replayView.hidden = !isMsgVCCome;
  185. // 这里获取需要userid 一定要在cell赋值userid 之后再调用
  186. //
  187. _replayImgV.alpha = 1-([self.userId intValue] == [SHIKU_TRANSFER intValue]);
  188. }
  189. - (void)didQuickReply {
  190. if ([self.userId intValue] == [SHIKU_TRANSFER intValue]) {
  191. return;
  192. }
  193. if (self.delegate && [self.delegate respondsToSelector:self.didReplay]) {
  194. [self.delegate performSelectorOnMainThread:self.didReplay withObject:self waitUntilDone:YES];
  195. }
  196. }
  197. //将所有Cell的badge存到沙盒里
  198. //- (void)saveBadge:(NSString*)badg withTitle:(NSString*)titl{
  199. //
  200. // if (bage == nil || titl == nil) {
  201. // return;
  202. // }
  203. // NSArray * path = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  204. // NSString * cacherDir = [[path objectAtIndex:0] stringByAppendingPathComponent:@"cellBage.txt"];
  205. //
  206. // NSData * data = [[NSData alloc]initWithContentsOfFile:cacherDir];
  207. //
  208. // NSKeyedUnarchiver * unarchiver = [[NSKeyedUnarchiver alloc]initForReadingWithData:data];
  209. //
  210. // self.bageDict = [unarchiver decodeObjectForKey:@"dict"];
  211. //
  212. // if (self.bageDict == nil) {
  213. // self.bageDict = [[NSMutableDictionary alloc]init];
  214. // }
  215. //
  216. // [self.bageDict setObject:badg forKey:titl];
  217. //
  218. // NSMutableData * muData = [[NSMutableData alloc]init];
  219. //
  220. // NSKeyedArchiver * archiver = [[NSKeyedArchiver alloc]initForWritingWithMutableData:muData];
  221. //
  222. // [archiver encodeObject:self.bageDict forKey:@"dict"];
  223. //
  224. // [archiver finishEncoding];
  225. //
  226. // [muData writeToFile:cacherDir atomically:YES];
  227. //}
  228. //- (void)awakeFromNib
  229. //{
  230. // // Initialization code
  231. //}
  232. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  233. {
  234. [super setSelected:selected animated:animated];
  235. // Configure the view for the selected state
  236. }
  237. -(void)headImageDidTouch{
  238. if (self.delegate && [self.delegate respondsToSelector:didTouch]) {
  239. [self.delegate performSelectorOnMainThread:didTouch withObject:self.dataObj waitUntilDone:YES];
  240. }
  241. }
  242. - (void)getHeadImage{
  243. if(headImage){
  244. if([headImage rangeOfString:@"http://"].location == NSNotFound)
  245. self.headImageView.image = [UIImage imageNamed:headImage];
  246. else
  247. [g_server getImage:headImage imageView:self.headImageView];
  248. }
  249. [g_server getHeadImageSmall:userId userName:self.title imageView:self.headImageView];
  250. }
  251. -(void)setBage:(NSString *)s{
  252. // bageNumber.hidden = [s intValue]<=0;
  253. _replayImgV.hidden = [s intValue] > 0;
  254. _bageNumber.badgeString = s;
  255. if ([s intValue] >= 10 && [s intValue] <= 99) {
  256. _bageNumber.lb.font = SYSFONT(12);
  257. }else if ([s intValue] > 0 && [s intValue] < 10) {
  258. _bageNumber.lb.font = SYSFONT(13);
  259. }else if([s intValue] > 99){
  260. _bageNumber.lb.font = SYSFONT(9);
  261. }
  262. bage = s;
  263. }
  264. -(void)setForTimeLabel:(NSString *)s{
  265. self.bottomTitle = s;
  266. // self.bottomTitle = [s retain];
  267. self.timeLabel.text = s;
  268. }
  269. // 设置昵称和备注
  270. -(void)setTitle:(NSString *)s{
  271. // title = [s retain]; guanFLbTitle
  272. title = s;
  273. if ([s isEqualToString:@"客服公众号"]) {
  274. _guanFLbTitle.hidden=NO;
  275. self.lbTitle.text = [NSString stringWithFormat:@"%@",@"即信"];
  276. }else{
  277. self.lbTitle.text = [NSString stringWithFormat:@"%@",s];
  278. self.guanFLbTitle.hidden=YES;
  279. }
  280. }
  281. -(void)setPositionTitle:(NSString *)positionTitle{
  282. _positionTitle = positionTitle;
  283. if (positionTitle.length > 0) {
  284. _positionLabel.text = positionTitle;
  285. _positionLabel.hidden = NO;
  286. CGSize positionSize =[positionTitle sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11]}];
  287. if (positionSize.width >150)
  288. positionSize.width = 150;
  289. CGSize titleSize = [self.lbTitle.text sizeWithAttributes:@{NSFontAttributeName: self.lbTitle.font}];
  290. _positionLabel.frame = CGRectMake(self.lbTitle.frame.origin.x + titleSize.width + 2, CGRectGetMinY(self.lbTitle.frame) + 5, positionSize.width+4, positionSize.height);
  291. _positionLabel.center = CGPointMake(_positionLabel.center.x, 54 / 2);
  292. }
  293. }
  294. - (void)setSuLabel:(NSString *)s{
  295. // subtitle = [s retain];
  296. if ([title isEqualToString:@"客服公众号"]) {
  297. self.lbSubTitle.attributedText = [self setContentLabelStr:@""];
  298. }else{
  299. _subtitle = s;
  300. self.lbSubTitle.attributedText = [self setContentLabelStr:s];
  301. }
  302. }
  303. -(void)setSubtitle:(NSString *)subtitle{
  304. _subtitle = subtitle;
  305. self.lbSubTitle.attributedText = [self setContentLabelStr:subtitle];
  306. }
  307. //- (void)getMessageRange:(NSString*)message :(NSMutableArray*)array {
  308. //
  309. // NSRange range=[message rangeOfString: @"["];
  310. //
  311. // NSRange range1=[message rangeOfString: @"]"];
  312. //
  313. //
  314. // // 动画过滤
  315. // if ([message isEqualToString:[NSString stringWithFormat:@"[%@]",Localized(@"emojiVC_Emoji")]]) {
  316. // [array addObject:message];
  317. // return;
  318. // }
  319. //
  320. //
  321. // //判断当前字符串是否还有表情的标志。
  322. //
  323. // if (range.length>0 && range1.length>0 && range1.location > range.location) {
  324. //
  325. // if (range.location > 0) {
  326. //
  327. // [array addObject:[message substringToIndex:range.location]];
  328. //
  329. // [array addObject:[message substringWithRange:NSMakeRange(range.location, range1.location+1-range.location)]];
  330. //
  331. // NSString *str=[message substringFromIndex:range1.location+1];
  332. //
  333. // [self getMessageRange:str :array];
  334. //
  335. // }else {
  336. //
  337. // NSString *nextstr=[message substringWithRange:NSMakeRange(range.location, range1.location+1-range.location)];
  338. //
  339. // //排除文字是“”的
  340. //
  341. // if (![nextstr isEqualToString:@""]) {
  342. //
  343. // [array addObject:nextstr];
  344. //
  345. // NSString *str=[message substringFromIndex:range1.location+1];
  346. //
  347. // [self getMessageRange:str :array];
  348. //
  349. // }else {
  350. //
  351. // return;
  352. //
  353. // }
  354. //
  355. // }
  356. //
  357. // } else if (message != nil) {
  358. //
  359. // [array addObject:message];
  360. //
  361. // }
  362. //
  363. //}
  364. - (void)getMessageRange:(NSString*)message :(NSMutableArray*)array {
  365. NSRange range=[message rangeOfString: @"["];
  366. NSRange range1=[message rangeOfString: @"]"];
  367. // 动画过滤
  368. if ([message isEqualToString:[NSString stringWithFormat:@"[%@]",Localized(@"emojiVC_Emoji")]]) {
  369. [array addObject:message];
  370. return;
  371. }
  372. //判断当前字符串是否还有表情的标志。
  373. if (range.length>0 && range1.length>0 && range1.location > range.location) {
  374. if (range.location > 0) {
  375. NSString *str = [message substringToIndex:range.location];
  376. NSString *str1 = [message substringFromIndex:range.location];
  377. [array addObject:str];
  378. [self getMessageRange:str1 :array];
  379. }else {
  380. NSString *emojiString = [message substringWithRange:NSMakeRange(range.location + 1, range1.location - 1)];
  381. BOOL isEmoji = NO;
  382. NSString *str;
  383. NSString *str1;
  384. for (NSMutableDictionary *dic in g_constant.emojiArray) {
  385. NSString *emoji = [dic objectForKey:@"english"];
  386. if ([emoji isEqualToString:emojiString]) {
  387. isEmoji = YES;
  388. break;
  389. }
  390. }
  391. if (isEmoji) {
  392. str = [message substringWithRange:NSMakeRange(range.location, range1.location + 1)];
  393. str1 = [message substringFromIndex:range1.location + 1];
  394. [array addObject:str];
  395. }else{
  396. NSString *posString = [message substringWithRange:NSMakeRange(range.location + 1, range1.location)];
  397. NSRange posRange = [posString rangeOfString:@"["];
  398. if (posRange.location != NSNotFound) {
  399. str = [message substringToIndex:posRange.location + 1];
  400. str1 = [message substringFromIndex:posRange.location + 1];
  401. [array addObject:str];
  402. }else{
  403. str = [message substringToIndex:range1.location + 1];
  404. str1 = [message substringFromIndex:range1.location + 1];
  405. [array addObject:str];
  406. }
  407. }
  408. [self getMessageRange:str1 :array];
  409. }
  410. }else if (range.length>0 && range1.length>0 && range1.location < range.location){
  411. NSString *str = [message substringToIndex:range1.location + 1];
  412. NSString *str1 = [message substringFromIndex:range1.location + 1];
  413. [array addObject:str];
  414. [self getMessageRange:str1 :array];
  415. }else if (message != nil) {
  416. [array addObject:message];
  417. }
  418. }
  419. - (NSAttributedString *) setContentLabelStr:(NSString *) str {
  420. NSMutableArray *contentArray = [NSMutableArray array];
  421. [self getMessageRange:str :contentArray];
  422. NSMutableAttributedString *strM = [[NSMutableAttributedString alloc] init];
  423. NSInteger count = contentArray.count;
  424. if (contentArray.count > 15) {
  425. count = 15;
  426. }
  427. for (NSInteger i = 0; i < count; i ++) {
  428. NSString *object = contentArray[i];
  429. // NSLog(@"%@",object);
  430. BOOL flag = NO;
  431. if ([object hasSuffix:@"]"]&&[object hasPrefix:@"["]) {
  432. //如果是表情用iOS中附件代替string在label上显示
  433. NSTextAttachment *imageStr = [[NSTextAttachment alloc]init];
  434. NSString *imageShortName = [object substringWithRange:NSMakeRange(1, object.length - 2)];
  435. for (NSInteger i = 0; i < g_constant.emojiArray.count; i ++) {
  436. NSDictionary *dict = g_constant.emojiArray[i];
  437. NSString *imageName = dict[@"english"];
  438. if ([imageName isEqualToString:imageShortName]) {
  439. imageStr.image = [UIImage imageNamed:dict[@"filename"]];
  440. flag = YES;
  441. break; }
  442. }
  443. if (!flag) {
  444. [strM appendAttributedString:[[NSAttributedString alloc] initWithString:object]];
  445. NSRange range = [object rangeOfString:Localized(@"JX_Draft")];
  446. [strM addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range];
  447. range = [object rangeOfString:Localized(@"JX_Someone@Me")];
  448. [strM addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range];
  449. continue;
  450. }
  451. // imageStr.image = [UIImage imageNamed:[object substringWithRange:NSMakeRange(1, object.length - 2)]];
  452. //这里对图片的大小进行设置一般来说等于文字的高度
  453. CGFloat height = self.lbSubTitle.font.lineHeight + 1;
  454. imageStr.bounds = CGRectMake(0, -4, height, height);
  455. NSAttributedString *attrString = [NSAttributedString attributedStringWithAttachment:imageStr];
  456. [strM appendAttributedString:attrString];
  457. }else{
  458. //如果不是表情直接进行拼接
  459. [strM appendAttributedString:[[NSAttributedString alloc] initWithString:object]];
  460. NSRange range = [object rangeOfString:Localized(@"JX_Draft")];
  461. [strM addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range];
  462. range = [object rangeOfString:Localized(@"JX_Someone@Me")];
  463. [strM addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range];
  464. }
  465. }
  466. return strM;
  467. }
  468. -(void)headImageNotification:(NSNotification *)notification{
  469. NSDictionary * groupDict = notification.object;
  470. NSString * roomJid = groupDict[@"roomJid"];
  471. if ([roomJid isEqualToString:self.userId]) {
  472. UIImage * hImage = groupDict[@"groupHeadImage"];
  473. self.headImageView.image = hImage;
  474. }
  475. }
  476. -(void)headImageViewImageWithUserId:(NSString *)userId roomId:(NSString *)roomIdStr {
  477. if (roomIdStr != nil) {
  478. // if (![g_server getRoomHeadImageSmall:self.userId imageView:self.headImageView]) {
  479. // NSString *groupImagePath = [NSString stringWithFormat:@"%@%@/%@.%@",NSTemporaryDirectory(),g_myself.userId,roomIdStr,@"jpg"];
  480. // if (groupImagePath && [[NSFileManager defaultManager] fileExistsAtPath:groupImagePath]) {
  481. // self.headImageView.image = [UIImage imageWithContentsOfFile:groupImagePath];
  482. // }else{
  483. // [roomData roomHeadImageRoomId:roomIdStr toView:self.headImageView];
  484. // }
  485. [g_server getRoomHeadImageSmall:userId roomId:roomIdStr imageView:self.headImageView];
  486. // }
  487. }else{
  488. if(headImage){
  489. if([headImage rangeOfString:@"http://"].location == NSNotFound)
  490. self.headImageView.image = [UIImage imageNamed:headImage];
  491. else
  492. [g_server getImage:headImage imageView:self.headImageView];
  493. }
  494. [g_server getHeadImageSmall:self.userId userName:self.title imageView:self.headImageView];
  495. }
  496. }
  497. - (void)setIsSmall:(BOOL)isSmall {
  498. _isSmall = isSmall;
  499. CGFloat headX = 14;
  500. self.delBtn.hidden = YES;
  501. if (self.isEdit) {
  502. self.delBtn.hidden = NO;
  503. headX = CGRectGetMaxX(_delBtn.frame) + 10;
  504. }
  505. if (!isSmall) {
  506. _headImageView.frame = CGRectMake(headX,8,52,52);
  507. self.lbTitle.frame = CGRectMake(CGRectGetMaxX(_headImageView.frame)+15, 15, JX_SCREEN_WIDTH - 115 -CGRectGetMaxX(_headImageView.frame)-14, 18);
  508. self.lbSubTitle.frame = CGRectMake(CGRectGetMaxX(_headImageView.frame)+15, self.lbSubTitle.frame.origin.y, JX_SCREEN_WIDTH - 55 -CGRectGetMaxX(_headImageView.frame)-14, self.lbSubTitle.frame.size.height);
  509. self.lineView.frame = CGRectMake(CGRectGetMaxX(_headImageView.frame)+15,68-LINE_WH,JX_SCREEN_WIDTH,LINE_WH);
  510. }else {
  511. if (self.isShowNicknameRemarkNameTelphoneNumber) {
  512. _headImageView.frame = CGRectMake(headX,8,52,52);
  513. self.lbTitle.frame = CGRectMake(CGRectGetMaxX(_headImageView.frame)+15, 15, JX_SCREEN_WIDTH - 115 -CGRectGetMaxX(_headImageView.frame)-14, 18);
  514. self.lbSubTitle.frame = CGRectMake(CGRectGetMaxX(_headImageView.frame)+15, self.lbSubTitle.frame.origin.y, JX_SCREEN_WIDTH - 55 -CGRectGetMaxX(_headImageView.frame)-14, self.lbSubTitle.frame.size.height);
  515. self.lineView.frame = CGRectMake(CGRectGetMaxX(_headImageView.frame)+15,68-LINE_WH,JX_SCREEN_WIDTH,LINE_WH);
  516. }else {
  517. _headImageView.frame = CGRectMake(headX,9.5,40,40);
  518. _headImageView.layer.cornerRadius = _headImageView.frame.size.width / 2;
  519. self.lbTitle.frame = CGRectMake(CGRectGetMaxX(_headImageView.frame)+15, 21.5, JX_SCREEN_WIDTH - 115 -CGRectGetMaxX(_headImageView.frame)-14, 18);
  520. self.lbSubTitle.frame = CGRectMake(CGRectGetMaxX(_headImageView.frame)+15, self.lbSubTitle.frame.origin.y, JX_SCREEN_WIDTH - 55 -CGRectGetMaxX(_headImageView.frame)-14, self.lbSubTitle.frame.size.height);
  521. self.lineView.frame = CGRectMake(CGRectGetMaxX(_headImageView.frame)+15,59-LINE_WH,JX_SCREEN_WIDTH,LINE_WH);
  522. }
  523. }
  524. }
  525. @end