CommonStatusView.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // CommonStatusView.m
  3. // UniversalApp
  4. //
  5. // Created by bogokj on 2019/11/19.
  6. // Copyright © 2019 voidcat. All rights reserved.
  7. //
  8. #import "CommonStatusView.h"
  9. @interface CommonStatusView ()
  10. @property (strong, nonatomic) UIView *indicatorView;
  11. @property (strong, nonatomic) UILabel *indicatorLabel;
  12. @end
  13. @implementation CommonStatusView
  14. - (instancetype)initWithFrame:(CGRect)frame{
  15. if (self = [super initWithFrame:frame]) {
  16. self.backgroundColor = [UIColor colorWithHexString:@"#E5E5E5"];
  17. self.layer.cornerRadius = 10;
  18. self.clipsToBounds = YES;
  19. [self addSubview:self.indicatorView];
  20. [self addSubview:self.indicatorLabel];
  21. [self.indicatorView mas_makeConstraints:^(MASConstraintMaker *make) {
  22. make.size.mas_equalTo(CGSizeMake(5, 5));
  23. make.left.equalTo(self).offset(5);
  24. make.centerY.equalTo(self);
  25. }];
  26. [self.indicatorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  27. make.left.equalTo(self.indicatorView.mas_right).offset(5);
  28. make.centerY.equalTo(self.indicatorView);
  29. }];
  30. }
  31. return self;
  32. }
  33. - (void)awakeFromNib{
  34. [super awakeFromNib];
  35. self.backgroundColor = [UIColor colorWithHexString:@"#E5E5E5"];
  36. self.layer.cornerRadius = 10;
  37. self.clipsToBounds = YES;
  38. [self addSubview:self.indicatorView];
  39. [self addSubview:self.indicatorLabel];
  40. [self.indicatorView mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.size.mas_equalTo(CGSizeMake(5, 5));
  42. make.left.equalTo(self).offset(5);
  43. make.centerY.equalTo(self);
  44. }];
  45. [self.indicatorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.left.equalTo(self.indicatorView.mas_right).offset(5);
  47. make.centerY.equalTo(self.indicatorView);
  48. make.right.equalTo(self).offset(-5);
  49. }];
  50. }
  51. - (void)setType:(CommonStatusViewType)type{
  52. _type = type;
  53. switch (type) {
  54. case CommonStatusViewTypeOnline:
  55. self.indicatorView.backgroundColor = [UIColor colorWithHexString:@"#0ABA07"];
  56. self.indicatorLabel.text = NSLocalizedString(@"在线",nil);
  57. break;
  58. case CommonStatusViewTypeBlindDate:
  59. self.indicatorView.backgroundColor = [UIColor colorWithHexString:@"#FC3382"];
  60. self.indicatorLabel.text = NSLocalizedString(@"相亲中",nil);
  61. break;
  62. case CommonStatusViewTypeManyPeople:
  63. self.indicatorView.backgroundColor = [UIColor colorWithHexString:@"#FFC74C"];
  64. self.indicatorLabel.text = NSLocalizedString(@"交友中",nil);
  65. break;
  66. default:
  67. break;
  68. }
  69. }
  70. - (CGSize)sizeThatFits:(CGSize)size{
  71. CGSize lableSize = [self.indicatorLabel sizeThatFits:size];
  72. return CGSizeMake(lableSize.width + 10, 20);
  73. }
  74. - (UIView *)indicatorView{
  75. if (!_indicatorView) {
  76. _indicatorView = [[UIView alloc]initWithFrame:CGRectZero];
  77. _indicatorView.clipsToBounds = YES;
  78. _indicatorView.layer.cornerRadius = 2.5;
  79. }
  80. return _indicatorView;
  81. }
  82. - (UILabel *)indicatorLabel{
  83. if (!_indicatorLabel) {
  84. _indicatorLabel = [[UILabel alloc]initWithFrame:CGRectZero];
  85. _indicatorLabel.textColor = [UIColor colorWithHexString:@"333333"];
  86. _indicatorLabel.font = [UIFont systemFontOfSize:11];
  87. }
  88. return _indicatorLabel;
  89. }
  90. @end