ZZTextImgView.m 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //
  2. // ZZTextImgView.m
  3. // Pods
  4. //
  5. // Created by Max on 2021/1/14.
  6. //
  7. #import "ZZTextImgView.h"
  8. @implementation ZZTextImgView
  9. -(instancetype)initWithDirection:(ZZDirection)direction widgetAlign:(ZZTextImgAlign)widgetAlign{
  10. if (self == [super init]) {
  11. _lab = [[UILabel alloc] init];
  12. _imgV = [[UIImageView alloc] init];
  13. _inner = [[UIStackView alloc] init];
  14. _inner.axis = direction;
  15. [_inner addArrangedSubview:_imgV];
  16. if (widgetAlign == ZZTextImgAlignNormal) {
  17. [_inner addArrangedSubview:_lab];
  18. }else{
  19. [_inner insertArrangedSubview:_lab atIndex:0];
  20. }
  21. _inner.distribution = UIStackViewDistributionFill;
  22. _inner.alignment = UIStackViewAlignmentCenter;
  23. [self addArrangedSubview:_inner];
  24. self.axis = direction == ZZDirectionVertical ? ZZDirectionHorizontal : ZZDirectionVertical;
  25. self.distribution = UIStackViewDistributionEqualSpacing;
  26. self.alignment = UIStackViewAlignmentCenter;
  27. }
  28. return self;
  29. }
  30. @end