LKS_LocalInspectPanelLabelView.m 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifdef SHOULD_COMPILE_LOOKIN_SERVER
  2. //
  3. // LKS_LocalInspectPanelLabelView.m
  4. // LookinServer
  5. //
  6. // Created by Li Kai on 2019/5/15.
  7. // https://lookin.work
  8. //
  9. #import "LKS_LocalInspectPanelLabelView.h"
  10. #import "LookinServerDefines.h"
  11. @implementation LKS_LocalInspectPanelLabelView {
  12. CGFloat _horInset;
  13. }
  14. - (instancetype)initWithFrame:(CGRect)frame {
  15. if (self = [super initWithFrame:frame]) {
  16. _horInset = 8;
  17. _interspace = 10;
  18. self.userInteractionEnabled = NO;
  19. self.leftLabel = [UILabel new];
  20. self.leftLabel.textAlignment = NSTextAlignmentLeft;
  21. [self addSubview:self.leftLabel];
  22. self.rightLabel = [UILabel new];
  23. self.rightLabel.textAlignment = NSTextAlignmentRight;
  24. [self addSubview:self.rightLabel];
  25. }
  26. return self;
  27. }
  28. - (void)layoutSubviews {
  29. [super layoutSubviews];
  30. self.leftLabel.frame = CGRectMake(_horInset, 0, self.leftLabel.lks_bestWidth, self.bounds.size.height);
  31. if (self.rightLabel.text.length) {
  32. CGFloat rightLabelWidth = self.bounds.size.width - _horInset - _interspace - CGRectGetMaxX(self.leftLabel.frame);
  33. if (rightLabelWidth <= 0) {
  34. self.rightLabel.frame = CGRectZero;
  35. } else {
  36. self.rightLabel.frame = CGRectMake(CGRectGetMaxX(self.leftLabel.frame) + _interspace, 0, rightLabelWidth, self.bounds.size.height);
  37. }
  38. }
  39. self.bottomBorderLayer.frame = CGRectMake(_horInset, self.bounds.size.height, self.bounds.size.width - _horInset * 2, 1 / [[UIScreen mainScreen] scale]);
  40. }
  41. - (CGSize)sizeThatFits:(CGSize)size {
  42. CGSize leftSize = [self.leftLabel sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)];
  43. size.height = leftSize.height + self.verInset;
  44. size.width = _horInset * 2 + leftSize.width;
  45. if (self.rightLabel.text.length) {
  46. size.width += self.rightLabel.lks_bestWidth + _interspace;
  47. }
  48. return size;
  49. }
  50. - (void)addBottomBorderLayer {
  51. if (self.bottomBorderLayer) {
  52. return;
  53. }
  54. self.bottomBorderLayer = [CALayer new];
  55. [self.bottomBorderLayer lookin_removeImplicitAnimations];
  56. self.bottomBorderLayer.backgroundColor = [UIColor colorWithRed:222/255.0 green:224/255.0 blue:226/255.0 alpha:1].CGColor;
  57. [self.layer addSublayer:self.bottomBorderLayer];
  58. }
  59. @end
  60. #endif /* SHOULD_COMPILE_LOOKIN_SERVER */