EaseBubbleView.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.h"
  13. #import "EaseBubbleView+Text.h"
  14. #import "EaseBubbleView+Image.h"
  15. #import "EaseBubbleView+Location.h"
  16. #import "EaseBubbleView+Voice.h"
  17. #import "EaseBubbleView+Video.h"
  18. #import "EaseBubbleView+File.h"
  19. @interface EaseBubbleView()
  20. @property (nonatomic) NSLayoutConstraint *marginTopConstraint;
  21. @property (nonatomic) NSLayoutConstraint *marginBottomConstraint;
  22. @property (nonatomic) NSLayoutConstraint *marginLeftConstraint;
  23. @property (nonatomic) NSLayoutConstraint *marginRightConstraint;
  24. @end
  25. @implementation EaseBubbleView
  26. @synthesize backgroundImageView = _backgroundImageView;
  27. @synthesize margin = _margin;
  28. - (instancetype)initWithMargin:(UIEdgeInsets)margin
  29. isSender:(BOOL)isSender
  30. {
  31. self = [super init];
  32. if (self) {
  33. _isSender = isSender;
  34. _margin = margin;
  35. _marginConstraints = [NSMutableArray array];
  36. }
  37. return self;
  38. }
  39. #pragma mark - Setup Constraints
  40. /*!
  41. @method
  42. @brief 设置气泡背景图片的约束
  43. @discussion
  44. @result
  45. */
  46. - (void)_setupBackgroundImageViewConstraints
  47. {
  48. [self addConstraint:[NSLayoutConstraint constraintWithItem:_backgroundImageView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:0]];
  49. [self addConstraint:[NSLayoutConstraint constraintWithItem:_backgroundImageView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0]];
  50. [self addConstraint:[NSLayoutConstraint constraintWithItem:_backgroundImageView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0]];
  51. [self addConstraint:[NSLayoutConstraint constraintWithItem:_backgroundImageView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:0]];
  52. [self addConstraint:[NSLayoutConstraint constraintWithItem:_backgroundImageView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0]];
  53. }
  54. #pragma mark - getter
  55. - (UIImageView *)backgroundImageView
  56. {
  57. if (_backgroundImageView == nil) {
  58. _backgroundImageView = [[UIImageView alloc] init];
  59. _backgroundImageView.translatesAutoresizingMaskIntoConstraints = NO;
  60. _backgroundImageView.backgroundColor = [UIColor clearColor];
  61. [self addSubview:_backgroundImageView];
  62. [self _setupBackgroundImageViewConstraints];
  63. }
  64. return _backgroundImageView;
  65. }
  66. @end