CGXVerticalMenuCollectionSectionTextView.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // CGXVerticalMenuCollectionSectionTextView.m
  3. // CGXVerticalMenuView-OC
  4. //
  5. // Created by CGX on 2018/05/01.
  6. // Copyright © 2019 CGX. All rights reserved.
  7. //
  8. #import "CGXVerticalMenuCollectionSectionTextView.h"
  9. @implementation CGXVerticalMenuCollectionSectionTextView
  10. - (instancetype)initWithFrame:(CGRect)frame
  11. {
  12. self = [super initWithFrame:frame];
  13. if (self) {
  14. UILabel *ppLabel =[[UILabel alloc] init];
  15. ppLabel.textColor = [UIColor blackColor];
  16. ppLabel.font = [UIFont systemFontOfSize:14];
  17. ppLabel.numberOfLines = 0;
  18. ppLabel.textAlignment = NSTextAlignmentCenter;
  19. ppLabel.layer.masksToBounds = YES;
  20. ppLabel.layer.borderWidth = 0;
  21. ppLabel.layer.borderColor = [UIColor whiteColor].CGColor;
  22. ppLabel.layer.cornerRadius = 0;
  23. ppLabel.translatesAutoresizingMaskIntoConstraints = NO;
  24. [self addSubview:ppLabel];
  25. self.titleLabel = ppLabel;
  26. }
  27. return self;
  28. }
  29. - (void)updateWithTextModel:(CGXVerticalMenuCustomTextModel *)textModel
  30. {
  31. self.titleLabel.text = textModel.text;
  32. self.titleLabel.textColor = textModel.textColor;
  33. self.titleLabel.font = textModel.textFont;
  34. self.titleLabel.numberOfLines = textModel.numberOfLines;
  35. self.titleLabel.textAlignment = textModel.textAlignment;
  36. self.titleLabel.layer.borderWidth = textModel.borderWidth;
  37. self.titleLabel.layer.borderColor = textModel.borderColor.CGColor;
  38. self.titleLabel.layer.cornerRadius = textModel.borderRadius;
  39. self.titleLabel.backgroundColor = textModel.textBgColor;
  40. NSLayoutConstraint *top = [NSLayoutConstraint constraintWithItem:self.titleLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:textModel.spaceTop];
  41. NSLayoutConstraint *left = [NSLayoutConstraint constraintWithItem:self.titleLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:textModel.spaceLeft];
  42. NSLayoutConstraint *right = [NSLayoutConstraint constraintWithItem:self.titleLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:-textModel.spaceRight];
  43. NSLayoutConstraint *bottom = [NSLayoutConstraint constraintWithItem:self.titleLabel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-textModel.spaceBottom];
  44. [self addConstraint:top];
  45. [self addConstraint:left];
  46. [self addConstraint:right];
  47. [self addConstraint:bottom];
  48. }
  49. @end