Procházet zdrojové kódy

ZZTextImgView.h 里面又包了一层stackView

zzb před 4 roky
rodič
revize
631693920e

+ 1 - 0
ZZUIKit/Classes/ZZTextImgView/ZZTextImgView.h

@@ -26,6 +26,7 @@ typedef NS_ENUM(NSUInteger, ZZTextImgAlign) {
 @property(nonatomic,assign,readonly) ZZDirection direction;
 //排列方式
 @property(nonatomic,assign,readonly) ZZTextImgAlign widgetAlign;
+@property(nonatomic,strong) UIStackView *inner;
 @property(nonatomic,strong) UILabel *lab;
 @property(nonatomic,strong) UIImageView *imgV;
 @end

+ 11 - 5
ZZUIKit/Classes/ZZTextImgView/ZZTextImgView.m

@@ -11,17 +11,23 @@
 
 -(instancetype)initWithDirection:(ZZDirection)direction widgetAlign:(ZZTextImgAlign)widgetAlign{
     if (self == [super init]) {
-        self.axis = direction;
         _lab = [[UILabel alloc] init];
         _imgV = [[UIImageView alloc] init];
-        [self addArrangedSubview:_imgV];
+        
+        _inner = [[UIStackView alloc] init];
+        _inner.axis = direction;
+        [_inner addArrangedSubview:_imgV];
         if (widgetAlign == ZZTextImgAlignNormal) {
-            [self addArrangedSubview:_lab];
+            [_inner addArrangedSubview:_lab];
         }else{
-            [self insertArrangedSubview:_lab atIndex:0];
+            [_inner insertArrangedSubview:_lab atIndex:0];
         }
+        _inner.distribution = UIStackViewDistributionFill;
+        _inner.alignment = UIStackViewAlignmentCenter;
         
-        self.distribution = UIStackViewDistributionFill;
+        [self addArrangedSubview:_inner];
+        self.axis = direction == ZZDirectionVertical ? ZZDirectionHorizontal : ZZDirectionVertical;
+        self.distribution = UIStackViewDistributionEqualSpacing;
         self.alignment = UIStackViewAlignmentCenter;
     }
     return self;