EaseBubbleView+File.m 5.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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+File.h"
  13. @implementation EaseBubbleView (File)
  14. #pragma mark - private
  15. - (void)_setupFileBubbleMarginConstraints
  16. {
  17. [self.marginConstraints removeAllObjects];
  18. //icon view
  19. NSLayoutConstraint *fileIconWithMarginTopConstraint = [NSLayoutConstraint constraintWithItem:self.fileIconView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.backgroundImageView attribute:NSLayoutAttributeTop multiplier:1.0 constant:self.margin.top];
  20. NSLayoutConstraint *fileIconWithMarginBottomConstraint = [NSLayoutConstraint constraintWithItem:self.fileIconView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.backgroundImageView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-self.margin.bottom];
  21. NSLayoutConstraint *fileIconWithMarginLeftConstraint = [NSLayoutConstraint constraintWithItem:self.fileIconView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.backgroundImageView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:self.margin.left];
  22. [self.marginConstraints addObject:fileIconWithMarginTopConstraint];
  23. [self.marginConstraints addObject:fileIconWithMarginBottomConstraint];
  24. [self.marginConstraints addObject:fileIconWithMarginLeftConstraint];
  25. //name label
  26. NSLayoutConstraint *fileNameWithMarginTopConstraint = [NSLayoutConstraint constraintWithItem:self.fileNameLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.backgroundImageView attribute:NSLayoutAttributeTop multiplier:1.0 constant:self.margin.top];
  27. NSLayoutConstraint *fileNameWithMarginRightConstraint = [NSLayoutConstraint constraintWithItem:self.fileNameLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.backgroundImageView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-self.margin.right];
  28. [self.marginConstraints addObject:fileNameWithMarginTopConstraint];
  29. [self.marginConstraints addObject:fileNameWithMarginRightConstraint];
  30. //size label
  31. NSLayoutConstraint *fileSizeWithMarginBottomConstraint = [NSLayoutConstraint constraintWithItem:self.fileSizeLabel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.backgroundImageView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-self.margin.bottom];
  32. [self.marginConstraints addObject:fileSizeWithMarginBottomConstraint];
  33. [self addConstraints:self.marginConstraints];
  34. }
  35. - (void)_setupFileBubbleConstraints
  36. {
  37. [self _setupFileBubbleMarginConstraints];
  38. //icon view
  39. [self addConstraint:[NSLayoutConstraint constraintWithItem:self.fileIconView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.fileIconView attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0]];
  40. [self addConstraint:[NSLayoutConstraint constraintWithItem:self.fileNameLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.fileIconView attribute:NSLayoutAttributeRight multiplier:1.0 constant:EaseMessageCellPadding]];
  41. [self addConstraint:[NSLayoutConstraint constraintWithItem:self.fileSizeLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.fileNameLabel attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0]];
  42. [self addConstraint:[NSLayoutConstraint constraintWithItem:self.fileSizeLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.fileNameLabel attribute:NSLayoutAttributeRight multiplier:1.0 constant:0]];
  43. [self addConstraint:[NSLayoutConstraint constraintWithItem:self.fileSizeLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.fileNameLabel attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0]];
  44. }
  45. #pragma mark - public
  46. - (void)setupFileBubbleView
  47. {
  48. self.fileIconView = [[UIImageView alloc] init];
  49. self.fileIconView.translatesAutoresizingMaskIntoConstraints = NO;
  50. self.fileIconView.backgroundColor = [UIColor clearColor];
  51. self.fileIconView.contentMode = UIViewContentModeScaleAspectFit;
  52. [self.backgroundImageView addSubview:self.fileIconView];
  53. self.fileNameLabel = [[UILabel alloc] init];
  54. self.fileNameLabel.translatesAutoresizingMaskIntoConstraints = NO;
  55. self.fileNameLabel.backgroundColor = [UIColor clearColor];
  56. [self.backgroundImageView addSubview:self.fileNameLabel];
  57. self.fileSizeLabel = [[UILabel alloc] init];
  58. self.fileSizeLabel.translatesAutoresizingMaskIntoConstraints = NO;
  59. self.fileSizeLabel.backgroundColor = [UIColor clearColor];
  60. [self.backgroundImageView addSubview:self.fileSizeLabel];
  61. [self _setupFileBubbleConstraints];
  62. }
  63. - (void)updateFileMargin:(UIEdgeInsets)margin
  64. {
  65. if (_margin.top == margin.top && _margin.bottom == margin.bottom && _margin.left == margin.left && _margin.right == margin.right) {
  66. return;
  67. }
  68. _margin = margin;
  69. [self removeConstraints:self.marginConstraints];
  70. [self _setupFileBubbleMarginConstraints];
  71. }
  72. @end