Açıklama Yok

CustomerListCell.m 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /************************************************************
  2. * * EaseMob CONFIDENTIAL
  3. * __________________
  4. * Copyright (C) 2013-2014 EaseMob Technologies. All rights reserved.
  5. *
  6. * NOTICE: All information contained herein is, and remains
  7. * the property of EaseMob Technologies.
  8. * Dissemination of this information or reproduction of this material
  9. * is strictly forbidden unless prior written permission is obtained
  10. * from EaseMob Technologies.
  11. */
  12. #import "CustomerListCell.h"
  13. @implementation CustomerListCell
  14. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  15. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  16. if (self) {
  17. self.contentView.backgroundColor = [UIColor whiteColor];
  18. self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  19. [self layoutAllComponents];
  20. }
  21. return self;
  22. }
  23. #pragma mark - Generate Properties
  24. - (APAvatarImageView *)headView {
  25. if (!_headView) {
  26. _headView = [[APAvatarImageView alloc] init];
  27. _headView.borderColor = [UIColor whiteColor];
  28. _headView.borderWidth = 0.0;
  29. _headView.cornerRadius = 3.0;
  30. }
  31. return _headView;
  32. }
  33. - (UILabel *)nickLabel {
  34. if (!_nickLabel) {
  35. _nickLabel = [[UILabel alloc] init];
  36. _nickLabel.font = [UIFont systemFontOfSize:14.0];
  37. _nickLabel.textColor = [UIColor blackColor];
  38. // _nickLabel.backgroundColor = [UIColor redColor];
  39. }
  40. return _nickLabel;
  41. }
  42. - (UILabel *)messageLabel {
  43. if (!_messageLabel) {
  44. _messageLabel = [[UILabel alloc] init];
  45. _messageLabel.font = [UIFont systemFontOfSize:13.0];
  46. _messageLabel.textColor = UIColorFromRGB(0x999999);
  47. }
  48. return _messageLabel;
  49. }
  50. - (UILabel *)timeLabel {
  51. if (!_timeLabel) {
  52. _timeLabel = [[UILabel alloc] init];
  53. _timeLabel.font = [UIFont systemFontOfSize:12.0];
  54. _timeLabel.textAlignment = NSTextAlignmentRight;
  55. _timeLabel.textColor = [UIColor lightGrayColor];
  56. // _timeLabel.backgroundColor = [UIColor redColor];
  57. }
  58. return _timeLabel;
  59. }
  60. - (UILabel *)unreadLabel {
  61. if (!_unreadLabel) {
  62. _unreadLabel = [[UILabel alloc] init];
  63. _unreadLabel.textColor = [UIColor whiteColor];
  64. _unreadLabel.backgroundColor = UIColorFromRGB(0x00c8a9);
  65. _unreadLabel.textAlignment = NSTextAlignmentCenter;
  66. _unreadLabel.font = [UIFont systemFontOfSize:11];
  67. _unreadLabel.layer.cornerRadius = 8;
  68. _unreadLabel.clipsToBounds = YES;
  69. }
  70. return _unreadLabel;
  71. }
  72. #pragma mark - Layout
  73. - (void)layoutAllComponents {
  74. WeakSelf(weakSelf);
  75. [self.contentView addSubview:self.headView];
  76. [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.left.equalTo(weakSelf.contentView).with.offset(15);
  78. make.centerY.equalTo(weakSelf.contentView);
  79. make.size.mas_equalTo(CGSizeMake(36, 36));
  80. }];
  81. [self.contentView addSubview:self.timeLabel];
  82. [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.right.equalTo(weakSelf.contentView).with.offset(-12);
  84. make.top.equalTo(weakSelf.headView.mas_top).with.offset(-2);
  85. make.size.mas_equalTo(CGSizeMake(100, 20));
  86. }];
  87. [self.contentView addSubview:self.nickLabel];
  88. [self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  89. make.left.equalTo(weakSelf.headView.mas_right).with.offset(14);
  90. make.right.equalTo(weakSelf.timeLabel.mas_left).with.offset(4);
  91. make.top.equalTo(weakSelf.headView.mas_top).with.offset(-2);
  92. make.height.mas_equalTo(20);
  93. }];
  94. [self.contentView addSubview:self.messageLabel];
  95. [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.left.equalTo(weakSelf.headView.mas_right).with.offset(14);
  97. make.right.equalTo(weakSelf.contentView).with.offset(-12);
  98. make.bottom.equalTo(weakSelf.headView.mas_bottom).with.offset(4);
  99. make.height.mas_equalTo(20);
  100. }];
  101. [self.contentView addSubview:self.unreadLabel];
  102. [self.unreadLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  103. make.left.equalTo(weakSelf.headView.mas_right).with.offset(-6);
  104. make.top.equalTo(weakSelf.headView.mas_top).with.offset(-6);
  105. make.width.mas_greaterThanOrEqualTo(16);
  106. make.height.mas_equalTo(16);
  107. }];
  108. }
  109. #pragma mark - Unread Label
  110. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  111. [super setSelected:selected animated:animated];
  112. if (![_unreadLabel isHidden]) {
  113. _unreadLabel.backgroundColor = [UIColor redColor];
  114. }
  115. }
  116. - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
  117. [super setHighlighted:highlighted animated:animated];
  118. if (![_unreadLabel isHidden]) {
  119. _unreadLabel.backgroundColor = [UIColor redColor];
  120. }
  121. }
  122. @end