@@ -30,7 +30,7 @@ -(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
30
30
31
31
MyFrameLayout *leftItemLayout = [self createItemLayout: NSLocalizedString(@" Show" , @" " ) withTag: 0 ];
32
32
leftItemLayout.widthDime .equalTo (rootLayout.widthDime ).multiply (1 /3.0 );
33
- leftItemLayout.marginGravity = MyMarginGravity_Vert_Fill | MyMarginGravity_Horz_Left ;
33
+ leftItemLayout.heightDime . equalTo (rootLayout. heightDime ) ;
34
34
leftItemLayout.highlightedOpacity = 0.5 ;
35
35
[rootLayout addSubview: leftItemLayout];
36
36
@@ -39,25 +39,30 @@ -(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
39
39
40
40
MyFrameLayout *centerItemLayout = [self createItemLayout: NSLocalizedString(@" Topic" , @" " ) withTag: 1 ];
41
41
centerItemLayout.widthDime .equalTo (rootLayout.widthDime ).multiply (1 /3.0 );
42
- centerItemLayout.marginGravity = MyMarginGravity_Vert_Fill | MyMarginGravity_Horz_Center;
42
+ centerItemLayout.heightDime .equalTo (rootLayout.heightDime );
43
+ centerItemLayout.centerXPos .equalTo (@0 );
43
44
centerItemLayout.leftBorderLine = bld;
44
45
centerItemLayout.highlightedOpacity = 0.5 ;
45
46
[rootLayout addSubview: centerItemLayout];
46
47
47
48
48
49
MyFrameLayout *rightItemLayout = [self createItemLayout: NSLocalizedString(@" Follow" , @" " ) withTag: 2 ];
49
50
rightItemLayout.widthDime .equalTo (rootLayout.widthDime ).multiply (1 /3.0 );
50
- rightItemLayout.marginGravity = MyMarginGravity_Vert_Fill | MyMarginGravity_Horz_Right;
51
+ rightItemLayout.heightDime .equalTo (rootLayout.heightDime );
52
+ rightItemLayout.rightPos .equalTo (@0 );
51
53
rightItemLayout.leftBorderLine = bld;
52
54
rightItemLayout.highlightedOpacity = 0.5 ;
53
55
[rootLayout addSubview: rightItemLayout];
54
56
55
57
// 底部的横线
56
58
_underLineView = [UIView new ];
57
- _underLineView.myHeight = 2 ;
58
59
_underLineView.backgroundColor = [UIColor redColor ];
59
60
_underLineView.widthDime .equalTo (rootLayout.widthDime ).multiply (1 /3.0 );
60
- _underLineView.marginGravity = MyMarginGravity_Vert_Bottom | MyMarginGravity_Horz_Left;
61
+ _underLineView.heightDime .equalTo (@2 );
62
+ _underLineView.bottomPos .equalTo (@0 );
63
+ _underLineView.leftPos .equalTo (@0 ).active = YES ; // 设置左边位置有效
64
+ _underLineView.centerXPos .equalTo (@0 ).active = NO ; // 设置水平中间位置无效
65
+ _underLineView.rightPos .equalTo (@0 ).active = NO ; // 设置右边位置无效
61
66
[rootLayout addSubview: _underLineView];
62
67
63
68
MyBorderLineDraw *rootLayoutBld = [[MyBorderLineDraw alloc ] initWithColor: [UIColor lightGrayColor ]];
@@ -89,7 +94,8 @@ -(MyFrameLayout*)createItemLayout:(NSString*)title withTag:(NSInteger)tag
89
94
titleLabel.text = title;
90
95
titleLabel.font = [UIFont systemFontOfSize: 15 ];
91
96
[titleLabel sizeToFit ];
92
- titleLabel.marginGravity = MyMarginGravity_Center; // 标题尺寸由内容包裹,位置在布局视图中居中。
97
+ titleLabel.centerXPos .equalTo (@0 );
98
+ titleLabel.centerYPos .equalTo (@0 ); // 标题尺寸由内容包裹,位置在布局视图中居中。
93
99
[itemLayout addSubview: titleLabel];
94
100
95
101
return itemLayout;
@@ -100,16 +106,22 @@ -(MyFrameLayout*)createItemLayout:(NSString*)title withTag:(NSInteger)tag
100
106
101
107
-(void )handleTap : (MyBaseLayout*)sender
102
108
{
103
- // 调整underLineView的marginGravity值来实现位置移动 。
109
+ // 调整underLineView的位置的有效值来实现位置移动。对于位置MyLayoutPos对象和尺寸对象MyLayoutSize来说有一个active属性来设置是否这个约束有效 。
104
110
switch (sender.tag ) {
105
111
case 0 :
106
- self.underLineView .marginGravity = MyMarginGravity_Vert_Bottom | MyMarginGravity_Horz_Left;
112
+ self.underLineView .leftPos .active = YES ;
113
+ self.underLineView .centerXPos .active = NO ;
114
+ self.underLineView .rightPos .active = NO ;
107
115
break ;
108
116
case 1 :
109
- self.underLineView .marginGravity = MyMarginGravity_Vert_Bottom | MyMarginGravity_Horz_Center;
117
+ self.underLineView .leftPos .active = NO ;
118
+ self.underLineView .centerXPos .active = YES ;
119
+ self.underLineView .rightPos .active = NO ;
110
120
break ;
111
121
case 2 :
112
- self.underLineView .marginGravity = MyMarginGravity_Vert_Bottom | MyMarginGravity_Horz_Right;
122
+ self.underLineView .leftPos .active = NO ;
123
+ self.underLineView .centerXPos .active = NO ;
124
+ self.underLineView .rightPos .active = YES ;
113
125
break ;
114
126
default :
115
127
NSAssert (0 , @" oops!" );
0 commit comments