Skip to content

Commit

Permalink
更新和优化makeLayout方法。
Browse files Browse the repository at this point in the history
  • Loading branch information
@欧柏泉 committed Feb 4, 2017
1 parent b6bde29 commit 13f7207
Show file tree
Hide file tree
Showing 4 changed files with 274 additions and 31 deletions.
33 changes: 33 additions & 0 deletions MyLayout/Lib/MyBaseLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,39 @@
/*布局视图基类,基类不支持实例化对象*/
@interface MyBaseLayout : UIView


/*
布局视图里面的padding属性用来设置布局视图的内边距。内边距是指布局视图里面的子视图离自己距离。外边距则是视图与父视图之间的距离。
内边距是在自己的尺寸内离子视图的距离,而外边距则不是自己尺寸内离其他视图的距离。下面是内边距和外边距的效果图:
^
| topMargin
| width
+------------------------------+
| |------------>
| l r | rightMargin
| e topPadding i |
| f g |
| t +---------------+ h |
<----------| P | | t |
leftMargin| a | | P |
| d | subviews | a | height
| d | content | d |
| i | | d |
| n | | i |
| g +---------------+ n |
| g |
| bottomPadding |
+------------------------------+
|bottomMargin
|
V
如果一个布局视图中的每个子视图都离自己有一定的距离就可以通过设置布局视图的内边距来实现,而不需要为每个子视图都设置外边距。
*/

/**
* 设置布局视图四周的内边距值。所谓内边距是指布局视图内的所有子视图离布局视图四周的边距。通过为布局视图设置内边距可以减少为所有子视图设置外边距的工作,而外边距则是指视图离父视图四周的距离。
*/
Expand Down
15 changes: 9 additions & 6 deletions MyLayout/Lib/MyMaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#if TARGET_OS_IPHONE

/**
*专门为布局设置的简化操作类,以便在统一的地方进行布局设置
*专门为布局设置的简化操作类,以便在统一的地方进行布局设置,MyLayout提供了类似masonry的布局设置语法。
*/
@interface MyMaker : NSObject

Expand All @@ -29,6 +29,7 @@

-(MyMaker*)centerX;
-(MyMaker*)centerY;
-(MyMaker*)center;

-(MyMaker*)sizeToFit;

Expand All @@ -38,6 +39,7 @@
-(MyMaker*)leftPadding;
-(MyMaker*)bottomPadding;
-(MyMaker*)rightPadding;
-(MyMaker*)padding;
-(MyMaker*)wrapContentHeight;
-(MyMaker*)wrapContentWidth;
-(MyMaker*)reverseLayout;
Expand All @@ -50,7 +52,7 @@
//线性布局和流式布局独有
-(MyMaker*)orientation;
-(MyMaker*)gravity;
-(MyMaker*)subviewMargin;
-(MyMaker*)space;

//线性布局独有
-(MyMaker*)shrinkType;
Expand All @@ -59,8 +61,8 @@
-(MyMaker*)arrangedCount;
-(MyMaker*)autoArrange;
-(MyMaker*)arrangedGravity;
-(MyMaker*)subviewVertMargin;
-(MyMaker*)subviewHorzMargin;
-(MyMaker*)vertSpace;
-(MyMaker*)horzSpace;
-(MyMaker*)pagedCount;


Expand All @@ -77,12 +79,13 @@

//赋值操支持NSNumber,UIView,MyLayoutPos,MyLayoutSize, NSArray[MyLayoutSize]
-(MyMaker* (^)(id val))equalTo;
-(MyMaker* (^)(id val))min;
-(MyMaker* (^)(id val))max;

-(MyMaker* (^)(CGFloat val))offset;
-(MyMaker* (^)(CGFloat val))multiply;
-(MyMaker* (^)(CGFloat val))add;
-(MyMaker* (^)(CGFloat val))min;
-(MyMaker* (^)(CGFloat val))max;




Expand Down
62 changes: 51 additions & 11 deletions MyLayout/Lib/MyMaker.m
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ -(MyMaker*)rightPadding

}

-(MyMaker*)padding
{
[self addMethod:@"topPadding"];
[self addMethod:@"leftPadding"];
[self addMethod:@"bottomPadding"];
return [self addMethod:@"rightPadding"];
}

-(MyMaker*)orientation
{
Expand All @@ -193,6 +200,12 @@ -(MyMaker*)centerY
return [self addMethod:@"centerYPos"];
}

-(MyMaker*)center
{
[self addMethod:@"centerXPos"];
return [self addMethod:@"centerYPos"];
}

-(MyMaker*)sizeToFit
{
for (UIView *myView in _myViews)
Expand All @@ -210,7 +223,7 @@ -(MyMaker*)marginGravity

}

-(MyMaker*)subviewMargin
-(MyMaker*)space
{
return [self addMethod:@"subviewMargin"];

Expand Down Expand Up @@ -239,13 +252,13 @@ -(MyMaker*)arrangedGravity

}

-(MyMaker*)subviewVertMargin
-(MyMaker*)vertSpace
{
return [self addMethod:@"subviewVertMargin"];

}

-(MyMaker*)subviewHorzMargin
-(MyMaker*)horzSpace
{
return [self addMethod:@"subviewHorzMargin"];

Expand Down Expand Up @@ -377,37 +390,64 @@ -(MyMaker*)pagedCount

}

-(MyMaker* (^)(CGFloat val))min
-(MyMaker* (^)(id val))min
{
_clear = YES;
return ^id(CGFloat val) {
return ^id(id val) {

for (NSString *key in _keys)
{

for (UIView *myView in _myViews)
{

[((MyLayoutSize*)[myView valueForKey:key]) __min:val];

id val2 = val;
if ([val isKindOfClass:[UIView class]])
val2 = [val valueForKey:key];

id oldVal = [myView valueForKey:key];
if ([oldVal isKindOfClass:[MyLayoutPos class]])
{
[((MyLayoutPos*)oldVal) __lBound:val2 offsetVal:0];
}
else if ([oldVal isKindOfClass:[MyLayoutSize class]])
{
[((MyLayoutSize*)oldVal) __lBound:val2 addVal:0 multiVal:1];
}
else
;
}
}
return self;
};

}

-(MyMaker* (^)(CGFloat val))max
-(MyMaker* (^)(id val))max
{
_clear = YES;
return ^id(CGFloat val) {
return ^id(id val) {

for (NSString *key in _keys)
{

for (UIView *myView in _myViews)
{
id val2 = val;
if ([val isKindOfClass:[UIView class]])
val2 = [val valueForKey:key];

[((MyLayoutSize*)[myView valueForKey:key]) __max:val];
id oldVal = [myView valueForKey:key];
if ([oldVal isKindOfClass:[MyLayoutPos class]])
{
[((MyLayoutPos*)oldVal) __uBound:val2 offsetVal:0];
}
else if ([oldVal isKindOfClass:[MyLayoutSize class]])
{
[((MyLayoutSize*)oldVal) __uBound:val2 addVal:0 multiVal:1];
}
else
;
}
}
return self;
Expand Down
Loading

0 comments on commit 13f7207

Please sign in to comment.