EaseBubbleView+Image.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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+Image.h"
  13. @implementation EaseBubbleView (Image)
  14. #pragma mark - private
  15. - (void)_setupImageBubbleMarginConstraints
  16. {
  17. NSLayoutConstraint *marginTopConstraint = [NSLayoutConstraint constraintWithItem:self.imageView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.backgroundImageView attribute:NSLayoutAttributeTop multiplier:1.0 constant:self.margin.top];
  18. NSLayoutConstraint *marginBottomConstraint = [NSLayoutConstraint constraintWithItem:self.imageView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.backgroundImageView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-self.margin.bottom];
  19. NSLayoutConstraint *marginLeftConstraint = [NSLayoutConstraint constraintWithItem:self.imageView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.backgroundImageView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-self.margin.right];
  20. NSLayoutConstraint *marginRightConstraint = [NSLayoutConstraint constraintWithItem:self.imageView 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)_setupImageBubbleConstraints
  29. {
  30. [self _setupImageBubbleMarginConstraints];
  31. }
  32. #pragma mark - public
  33. - (void)setupImageBubbleView
  34. {
  35. self.imageView = [[UIImageView alloc] init];
  36. self.imageView.translatesAutoresizingMaskIntoConstraints = NO;
  37. self.imageView.backgroundColor = [UIColor clearColor];
  38. [self.backgroundImageView addSubview:self.imageView];
  39. [self _setupImageBubbleConstraints];
  40. }
  41. - (void)updateImageMargin:(UIEdgeInsets)margin
  42. {
  43. if (_margin.top == margin.top && _margin.bottom == margin.bottom && _margin.left == margin.left && _margin.right == margin.right) {
  44. return;
  45. }
  46. _margin = margin;
  47. [self removeConstraints:self.marginConstraints];
  48. [self _setupImageBubbleMarginConstraints];
  49. }
  50. @end