EMBadgeLabel.m 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //
  2. // EMBadgeLabel.m
  3. // ChatDemo-UI3.0
  4. //
  5. // Created by XieYajie on 2019/1/17.
  6. // Copyright © 2019 XieYajie. All rights reserved.
  7. //
  8. #import "EMBadgeLabel.h"
  9. @interface EMBadgeLabel()
  10. @property (nonatomic, strong) UILabel *badgeLabel;
  11. @end
  12. @implementation EMBadgeLabel
  13. - (instancetype)init
  14. {
  15. self = [super init];
  16. if (self) {
  17. self.backgroundColor = [UIColor redColor];
  18. _badgeLabel = [[UILabel alloc] init];
  19. _badgeLabel.font = [UIFont systemFontOfSize:13];
  20. _badgeLabel.textColor = [UIColor whiteColor];
  21. _badgeLabel.backgroundColor = [UIColor clearColor];
  22. [_badgeLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
  23. [self addSubview:_badgeLabel];
  24. [_badgeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  25. make.top.equalTo(self).offset(3);
  26. make.bottom.equalTo(self).offset(-3);
  27. make.left.equalTo(self).offset(3);
  28. make.right.equalTo(self).offset(-3);
  29. }];
  30. }
  31. return self;
  32. }
  33. - (void)setValue:(NSString *)value
  34. {
  35. self.badgeLabel.text = value;
  36. }
  37. - (void)setFont:(UIFont *)font
  38. {
  39. self.badgeLabel.font = font;
  40. }
  41. @end