EaseBubbleView+Text.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /************************************************************
  2. * * Hyphenate CONFIDENTIAL
  3. * __________________
  4. * Copyright (C) 2016 Hyphenate Inc. All rights reserved.
  5. *
  6. * NOTICE: All information contained herein is, and remains
  7. * the property of Hyphenate Inc.
  8. * Dissemination of this information or reproduction of this material
  9. * is strictly forbidden unless prior written permission is obtained
  10. * from Hyphenate Inc.
  11. */
  12. #import "EaseBubbleView+Text.h"
  13. @implementation EaseBubbleView (Text)
  14. #pragma mark - private
  15. - (void)_setupTextBubbleMarginConstraints
  16. {
  17. NSLayoutConstraint *marginTopConstraint = [NSLayoutConstraint constraintWithItem:self.textLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.backgroundImageView attribute:NSLayoutAttributeTop multiplier:1.0 constant:self.margin.top];
  18. NSLayoutConstraint *marginBottomConstraint = [NSLayoutConstraint constraintWithItem:self.textLabel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.backgroundImageView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-self.margin.bottom];
  19. NSLayoutConstraint *marginLeftConstraint = [NSLayoutConstraint constraintWithItem:self.textLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.backgroundImageView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-self.margin.right];
  20. NSLayoutConstraint *marginRightConstraint = [NSLayoutConstraint constraintWithItem:self.textLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.backgroundImageView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:self.margin.left];
  21. [self.marginConstraints removeAllObjects];
  22. [self.marginConstraints addObject:marginTopConstraint];
  23. [self.marginConstraints addObject:marginBottomConstraint];
  24. [self.marginConstraints addObject:marginLeftConstraint];
  25. [self.marginConstraints addObject:marginRightConstraint];
  26. [self addConstraints:self.marginConstraints];
  27. }
  28. - (void)_setupTextBubbleConstraints
  29. {
  30. [self _setupTextBubbleMarginConstraints];
  31. }
  32. #pragma mark - public
  33. - (void)setupTextBubbleView
  34. {
  35. self.textLabel = [[UILabel alloc] init];
  36. self.textLabel.accessibilityIdentifier = @"text_label";
  37. self.textLabel.translatesAutoresizingMaskIntoConstraints = NO;
  38. self.textLabel.backgroundColor = [UIColor clearColor];
  39. self.textLabel.numberOfLines = 0;
  40. [self.backgroundImageView addSubview:self.textLabel];
  41. [self _setupTextBubbleConstraints];
  42. }
  43. - (void)updateTextMargin:(UIEdgeInsets)margin
  44. {
  45. if (_margin.top == margin.top && _margin.bottom == margin.bottom && _margin.left == margin.left && _margin.right == margin.right) {
  46. return;
  47. }
  48. _margin = margin;
  49. [self removeConstraints:self.marginConstraints];
  50. [self _setupTextBubbleMarginConstraints];
  51. }
  52. @end