JXAnnounceCell.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // JXAnnounceCell.m
  3. // shiku_im
  4. //
  5. // Created by 1 on 2018/8/17.
  6. // Copyright © 2018年 Reese. All rights reserved.
  7. //
  8. #import "JXAnnounceCell.h"
  9. #define HEIGHT 36
  10. @interface JXAnnounceCell ()
  11. @property (nonatomic, strong) UIView *baseView;
  12. @property (nonatomic, strong) UIView *line;
  13. @end
  14. @implementation JXAnnounceCell
  15. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  16. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  17. if (self) {
  18. self.contentView.backgroundColor = HEXCOLOR(0xF2F2F2);
  19. self.baseView = [[UIView alloc] initWithFrame:CGRectMake(INSETS, INSETS, JX_SCREEN_WIDTH-INSETS*2, MAXFLOAT)];
  20. self.baseView.backgroundColor = [UIColor whiteColor];
  21. self.baseView.layer.masksToBounds = YES;
  22. self.baseView.layer.cornerRadius = 4.0f;
  23. [self.contentView addSubview:self.baseView];
  24. self.icon = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15, HEIGHT, HEIGHT)];
  25. self.icon.layer.masksToBounds = YES;
  26. self.icon.layer.cornerRadius = self.icon.frame.size.width/2;
  27. [self.baseView addSubview:self.icon];
  28. self.name = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.icon.frame)+15, 26, 200, 20)];
  29. self.name.font = SYSFONT(16);
  30. self.name.textColor = HEXCOLOR(0x333333);
  31. [self.baseView addSubview:self.name];
  32. self.time = [[UILabel alloc] initWithFrame:CGRectMake(self.baseView.frame.size.width-INSETS-100, self.name.frame.origin.y, 100, 20)];
  33. self.time.textAlignment = NSTextAlignmentRight;
  34. self.time.font = [UIFont systemFontOfSize:13];
  35. self.time.textColor = HEXCOLOR(0x333333);
  36. [self.baseView addSubview:self.time];
  37. self.line = [[UIView alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(self.icon.frame)+15, self.baseView.frame.size.width-15, LINE_WH)];
  38. self.line.backgroundColor = THE_LINE_COLOR;
  39. [self.baseView addSubview:self.line];
  40. self.content = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(self.line.frame)+20, self.baseView.frame.size.width-15*2, MAXFLOAT)];
  41. self.content.font = SYSFONT(16);
  42. self.content.numberOfLines = 0;
  43. self.content.textColor = HEXCOLOR(0x333333);
  44. [self.content sizeToFit];
  45. [self.baseView addSubview:self.content];
  46. }
  47. return self;
  48. }
  49. - (void)setCellHeightWithText:(NSString *)text {
  50. CGSize size = [text boundingRectWithSize:CGSizeMake(JX_SCREEN_WIDTH-INSETS*2-15*2, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:g_factory.font16} context:nil].size;
  51. self.content.frame = CGRectMake(15, CGRectGetMaxY(self.line.frame)+20,size.width, size.height);
  52. self.baseView.frame = CGRectMake(INSETS, INSETS, JX_SCREEN_WIDTH-INSETS*2, 106+size.height);
  53. }
  54. @end