Skip to content

Commit 48b18f8

Browse files
author
@欧柏泉
committed
升级到V1.1.8增加表格布局和智能边界线结合的功能。
1 parent 3ca00ac commit 48b18f8

14 files changed

+240
-32
lines changed

MyLayout.podspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
#
1717

1818
s.name = "MyLayout"
19-
s.version = "1.1.7"
19+
s.version = "1.1.8"
2020
s.summary = "A powerful iOS view layout library, suitable for all kinds of screen size. Don't need to learn AutoLayout and SizeClass. "
2121

2222
s.description = <<-DESC
@@ -79,7 +79,7 @@ Pod::Spec.new do |s|
7979
# Supports git, hg, bzr, svn and HTTP.
8080
#
8181

82-
s.source = { :git => "https://github.com/youngsoft/MyLinearLayout.git", :tag => "1.1.7" }
82+
s.source = { :git => "https://github.com/youngsoft/MyLinearLayout.git", :tag => "1.1.8" }
8383

8484

8585
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

MyLayout.xcodeproj/project.pbxproj

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
189692701CF74E7E000A5B91 /* AllTest2TableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 1896926F1CF74E7E000A5B91 /* AllTest2TableViewCell.m */; };
2121
189692731CF74EA7000A5B91 /* AllTest1TableViewHeaderFooterView.m in Sources */ = {isa = PBXBuildFile; fileRef = 189692721CF74EA7000A5B91 /* AllTest1TableViewHeaderFooterView.m */; };
2222
189692761CF74EC5000A5B91 /* AllTestDataModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 189692751CF74EC5000A5B91 /* AllTestDataModel.m */; };
23+
18CFFA2E1D0723970032A789 /* TLTest3ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 18CFFA2D1D0723970032A789 /* TLTest3ViewController.m */; };
2324
18D684301C4F421400A48BB4 /* AllTest1ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 18D683E81C4F421400A48BB4 /* AllTest1ViewController.m */; };
2425
18D684311C4F421400A48BB4 /* AllTest2ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 18D683EA1C4F421400A48BB4 /* AllTest2ViewController.m */; };
2526
18D684321C4F421400A48BB4 /* AllTest3ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 18D683EC1C4F421400A48BB4 /* AllTest3ViewController.m */; };
@@ -100,6 +101,8 @@
100101
189692721CF74EA7000A5B91 /* AllTest1TableViewHeaderFooterView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AllTest1TableViewHeaderFooterView.m; sourceTree = "<group>"; };
101102
189692741CF74EBB000A5B91 /* AllTestDataModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AllTestDataModel.h; sourceTree = "<group>"; };
102103
189692751CF74EC5000A5B91 /* AllTestDataModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AllTestDataModel.m; sourceTree = "<group>"; };
104+
18CFFA2C1D0723870032A789 /* TLTest3ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TLTest3ViewController.h; sourceTree = "<group>"; };
105+
18CFFA2D1D0723970032A789 /* TLTest3ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TLTest3ViewController.m; sourceTree = "<group>"; };
103106
18D683E71C4F421400A48BB4 /* AllTest1ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = AllTest1ViewController.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
104107
18D683E81C4F421400A48BB4 /* AllTest1ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = AllTest1ViewController.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
105108
18D683E91C4F421400A48BB4 /* AllTest2ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = AllTest2ViewController.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
@@ -295,6 +298,8 @@
295298
18D684291C4F421400A48BB4 /* RLTest3ViewController.m */,
296299
18D6842A1C4F421400A48BB4 /* TLTest1ViewController.h */,
297300
18D6842B1C4F421400A48BB4 /* TLTest1ViewController.m */,
301+
18CFFA2C1D0723870032A789 /* TLTest3ViewController.h */,
302+
18CFFA2D1D0723970032A789 /* TLTest3ViewController.m */,
298303
18D6842C1C4F421400A48BB4 /* TLTest2ViewController.h */,
299304
18D6842D1C4F421400A48BB4 /* TLTest2ViewController.m */,
300305
18296B6D1C76D55B00273C3E /* FOLTest1ViewController.h */,
@@ -475,6 +480,7 @@
475480
18D6844C1C4F421400A48BB4 /* main.m in Sources */,
476481
18D684441C4F421400A48BB4 /* MyTableLayout.m in Sources */,
477482
18D684421C4F421400A48BB4 /* MyMaker.m in Sources */,
483+
18CFFA2E1D0723970032A789 /* TLTest3ViewController.m in Sources */,
478484
188261CF1C647CB300996C2C /* AllTest6ViewController.m in Sources */,
479485
18D684401C4F421400A48BB4 /* MyLayoutPos.m in Sources */,
480486
18D684321C4F421400A48BB4 /* AllTest3ViewController.m in Sources */,

MyLayout/AllTest3ViewController.m

+3-2
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ -(MyLinearLayout*)createSwitchLayout:(NSString*)title action:(SEL)action
390390

391391
-(MyFloatLayout*)createSegmentedLayout:(SEL)leftAction rightAction:(SEL)rightAction
392392
{
393+
//建立一个左右浮动布局(注意左右浮动布局的orientation是MyLayoutViewOrientation_Vert)
393394
MyFloatLayout *segmentedLayout = [MyFloatLayout floatLayoutWithOrientation:MyLayoutViewOrientation_Vert];
394395
segmentedLayout.backgroundColor = [UIColor whiteColor];
395396

@@ -399,7 +400,7 @@ -(MyFloatLayout*)createSegmentedLayout:(SEL)leftAction rightAction:(SEL)rightAct
399400
segmentedLayout.heightDime.equalTo(@50);
400401
segmentedLayout.gravity = MyMarginGravity_Vert_Center;
401402

402-
403+
//向左浮动
403404
UISegmentedControl *leftSegmented = [[UISegmentedControl alloc] initWithItems:@[@"",@""]];
404405
leftSegmented.momentary = YES;
405406
[leftSegmented addTarget:self action:leftAction forControlEvents:UIControlEventValueChanged];
@@ -410,7 +411,7 @@ -(MyFloatLayout*)createSegmentedLayout:(SEL)leftAction rightAction:(SEL)rightAct
410411
rightSegmented.momentary = YES;
411412
[rightSegmented addTarget:self action:rightAction forControlEvents:UIControlEventValueChanged];
412413
[segmentedLayout addSubview:rightSegmented];
413-
rightSegmented.reverseFloat = YES;
414+
rightSegmented.reverseFloat = YES; //反向浮动也就是向右浮动。
414415

415416

416417
return segmentedLayout;

MyLayout/FOLTest5ViewController.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,18 @@ - (void)viewDidLoad {
7777
UILabel *titleLabel = [UILabel new];
7878
titleLabel.text = titles[i];
7979
titleLabel.textColor = colors[i];
80-
titleLabel.clearFloat = YES;
81-
titleLabel.widthDime.equalTo(rootLayout.widthDime).multiply(0.25);
80+
titleLabel.clearFloat = YES; //换行重新布局。
81+
titleLabel.widthDime.equalTo(rootLayout.widthDime).multiply(0.25); //宽度是父视图宽度的1/4
8282
titleLabel.adjustsFontSizeToFitWidth = YES;
8383
[titleLabel sizeToFit];
8484
[rootLayout addSubview:titleLabel];
8585

8686
UILabel *descLabel = [UILabel new];
8787
descLabel.text = descs[i];
8888
descLabel.font = [UIFont systemFontOfSize:14];
89-
descLabel.weight = 1;
89+
descLabel.weight = 1; //占用剩余的宽度
9090
descLabel.numberOfLines = 0;
91-
descLabel.flexedHeight = YES;
91+
descLabel.flexedHeight = YES; //多行自动换行。
9292
[descLabel sizeToFit];
9393
[rootLayout addSubview:descLabel];
9494

MyLayout/LLTest2ViewController.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ -(void)loadView
4545

4646

4747
/*
48-
布局视图里面的padding属性用来设置布局视图的内边距。内边距是指布局视图里面的子视图离自己间距。外边距则是布局视图与父视图或者兄弟视图之间的间距
48+
布局视图里面的padding属性用来设置布局视图的内边距。内边距是指布局视图里面的子视图离自己距离。外边距则是视图与父视图之间的距离
4949
内边距是在自己的尺寸内离子视图的距离,而外边距则不是自己尺寸内离其他视图的距离。下面是内边距和外边距的效果图:
5050
5151
^

MyLayout/LLTest3ViewController.m

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ -(void)createVertLayoutGravityActionLayout:(MyLinearLayout*)contentLayout
124124
-(void)createVertGravityLayout:(MyLinearLayout*)contentLayout
125125
{
126126
self.vertGravityLayout = [MyLinearLayout linearLayoutWithOrientation:MyLayoutViewOrientation_Vert];
127+
self.vertGravityLayout.wrapContentHeight = NO;
127128
self.vertGravityLayout.backgroundColor = [UIColor grayColor];
128129
self.vertGravityLayout.myHeight = 200;
129130
self.vertGravityLayout.myTopMargin = 10;

MyLayout/Lib/MyLayout.h

+12
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@
3434
SOFTWARE.
3535
*/
3636

37+
/*
38+
version1.1.8
39+
40+
New:
41+
1.优化了表格布局MyTableLayout和智能边界线的结合的问题。(具体见:TLTest3ViewController)
42+
2. 增加了浮动布局MyFloatLayout设置浮动间距的方法setSubviewFloatMargin (具体见:FOLTest4ViewController)
43+
44+
45+
*/
46+
3747
/*
3848
version1.1.7
3949
@@ -62,6 +72,8 @@
6272
6373
*/
6474

75+
76+
6577
#ifndef MyLayout_MyLayout_h
6678
#define MyLayout_MyLayout_h
6779

MyLayout/Lib/MyLinearLayout.m

+20-2
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,16 @@ -(CGRect)calcLayoutRect:(CGSize)size isEstimate:(BOOL)isEstimate pHasSubLayout:(
986986

987987
if (prevSiblingView != nil)
988988
{
989-
sbvl.topBorderLine = self.IntelligentBorderLine;
989+
BOOL ok = YES;
990+
if ([prevSiblingView isKindOfClass:[MyBaseLayout class]])
991+
{
992+
MyBaseLayout *prevSiblingLayout = (MyBaseLayout*)prevSiblingView;
993+
if (prevSiblingLayout.notUseIntelligentBorderLine)
994+
ok = NO;
995+
}
996+
997+
if (ok)
998+
sbvl.topBorderLine = self.IntelligentBorderLine;
990999
}
9911000

9921001
if (nextSiblingView != nil && ![nextSiblingView isKindOfClass:[MyBaseLayout class]])
@@ -1086,7 +1095,16 @@ -(CGRect)calcLayoutRect:(CGSize)size isEstimate:(BOOL)isEstimate pHasSubLayout:(
10861095

10871096
if (prevSiblingView != nil)
10881097
{
1089-
sbvl.leftBorderLine = self.IntelligentBorderLine;
1098+
BOOL ok = YES;
1099+
if ([prevSiblingView isKindOfClass:[MyBaseLayout class]])
1100+
{
1101+
MyBaseLayout *prevSiblingLayout = (MyBaseLayout*)prevSiblingView;
1102+
if (prevSiblingLayout.notUseIntelligentBorderLine)
1103+
ok = NO;
1104+
}
1105+
1106+
if (ok)
1107+
sbvl.leftBorderLine = self.IntelligentBorderLine;
10901108
}
10911109

10921110
if (nextSiblingView != nil && ![nextSiblingView isKindOfClass:[MyBaseLayout class]])

MyLayout/Lib/MyTableLayout.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@
4848
* @param rowSize 为MTLSIZE_WRAPCONTENT表示由子视图决定本行尺寸,子视图需要自己设置尺寸;为MTLSIZE_AVERAGE表示均分尺寸,子视图不需要设置尺寸;大于0表示固定尺寸,子视图不需要设置尺寸;不能设置为MTLSIZE_MATCHPARENT。
4949
* @param colSize 为MTLSIZE_MATCHPARENT表示子视图需要自己指定尺寸,整体行尺寸和父视图一样的尺寸;为MTLSIZE_WRAPCONTENT表示由子视图需要自己设置尺寸,行尺寸包裹所有子视图;为MTLSIZE_AVERAGE表示均分尺寸,这时候子视图不必设置尺寸;大于0表示子视图固定尺寸,这时候子视图可以不必设置尺寸。
5050
*/
51-
-(void)addRow:(CGFloat)rowSize colSize:(CGFloat)colSize;
51+
-(MyLinearLayout*)addRow:(CGFloat)rowSize colSize:(CGFloat)colSize;
5252

5353
/**
5454
* 在指定的位置插入一个新行
5555
*/
56-
-(void)insertRow:(CGFloat)rowSize colSize:(CGFloat)colSize atIndex:(NSInteger)rowIndex;
56+
-(MyLinearLayout*)insertRow:(CGFloat)rowSize colSize:(CGFloat)colSize atIndex:(NSInteger)rowIndex;
5757

5858
/**
5959
* 删除一行

MyLayout/Lib/MyTableLayout.m

+5-3
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ -(CGFloat)colSpacing
146146
}
147147

148148

149-
-(void)addRow:(CGFloat)rowSize colSize:(CGFloat)colSize
149+
-(MyLinearLayout*)addRow:(CGFloat)rowSize colSize:(CGFloat)colSize
150150
{
151-
[self insertRow:rowSize colSize:colSize atIndex:self.countOfRow];
151+
return [self insertRow:rowSize colSize:colSize atIndex:self.countOfRow];
152152
}
153153

154-
-(void)insertRow:(CGFloat)rowSize colSize:(CGFloat)colSize atIndex:(NSInteger)rowIndex
154+
-(MyLinearLayout*)insertRow:(CGFloat)rowSize colSize:(CGFloat)colSize atIndex:(NSInteger)rowIndex
155155
{
156156
MyLayoutViewOrientation ori = MyLayoutViewOrientation_Vert;
157157
if (self.orientation == MyLayoutViewOrientation_Vert)
@@ -161,7 +161,9 @@ -(void)insertRow:(CGFloat)rowSize colSize:(CGFloat)colSize atIndex:(NSInteger)ro
161161

162162
MyTableRowLayout *rowView = [MyTableRowLayout rowSize:rowSize colSize:colSize orientation:ori];
163163
rowView.subviewMargin = self.colSpacing;
164+
rowView.IntelligentBorderLine = self.IntelligentBorderLine;
164165
[super insertSubview:rowView atIndex:rowIndex];
166+
return rowView;
165167
}
166168

167169
-(void)removeRowAt:(NSInteger)rowIndex

MyLayout/TLTest3ViewController.h

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// TLT3ViewController.h
3+
// MyLayout
4+
//
5+
// Created by oybq on 15/7/18.
6+
// Copyright (c) 2015年 YoungSoft. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface TLTest3ViewController : UIViewController
12+
13+
@end

MyLayout/TLTest3ViewController.m

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
//
2+
// TLT3ViewController.m
3+
// MyLayout
4+
//
5+
// Created by oybq on 15/7/18.
6+
// Copyright (c) 2015年 YoungSoft. All rights reserved.
7+
//
8+
9+
#import "TLTest3ViewController.h"
10+
#import "MyLayout.h"
11+
12+
@interface TLTest3ViewController ()
13+
14+
@end
15+
16+
@implementation TLTest3ViewController
17+
18+
19+
-(void)loadView
20+
{
21+
/*
22+
这个例子是将表格布局和智能边界线的应用结合,实现一个表格界面。
23+
24+
*/
25+
[super loadView];
26+
27+
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectInset(self.view.bounds, 10, 10)];
28+
scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
29+
[self.view addSubview:scrollView];
30+
31+
//建立一个垂直表格
32+
MyTableLayout *tableLayout = [MyTableLayout tableLayoutWithOrientation:MyLayoutViewOrientation_Vert];
33+
tableLayout.myLeftMargin = tableLayout.myRightMargin = 0; //宽度和非布局父视图一样宽
34+
[scrollView addSubview:tableLayout];
35+
36+
37+
//建立一个表格外边界的边界线。颜色为黑色,粗细为3.
38+
MyBorderLineDraw *outerBorderLine = [[MyBorderLineDraw alloc] initWithColor:[UIColor blackColor]];
39+
outerBorderLine.thick = 3;
40+
tableLayout.boundBorderLine = outerBorderLine;
41+
42+
//建立智能边界线。所谓智能边界线就是布局里面的如果有子布局视图,则子布局视图会根据自身的布局位置智能的设置边界线。
43+
//智能边界线只支持表格布局、线性布局、流式布局、浮动布局。
44+
//如果要想完美使用智能分界线,则请将cellview建立为一个布局视图,比如本例子中的createCellLayout。
45+
MyBorderLineDraw *innerBorderLine = [[MyBorderLineDraw alloc] initWithColor:[UIColor redColor]];
46+
tableLayout.IntelligentBorderLine = innerBorderLine;
47+
48+
49+
//添加第一行。行高为50,每列宽由自己确定。
50+
MyLinearLayout *firstRow = [tableLayout addRow:50 colSize:MTLSIZE_MATCHPARENT];
51+
firstRow.notUseIntelligentBorderLine = YES; //因为智能边界线会影响到里面的所有子布局,包括每行,但是这里我们希望这行不受智能边界线的影响而想自己定义边界线,则将这个属性设置为YES。
52+
firstRow.bottomBorderLine = [[MyBorderLineDraw alloc] initWithColor:[UIColor blueColor]]; //我们自定义第一行的底部边界线为蓝色边界线。
53+
54+
NSArray *firstRowTitles = @[@"姓名",@"周一",@"周二",@"周三", @"周四",@"周五",@"周六",@"周日"];
55+
[firstRowTitles enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL * stop) {
56+
57+
UIView *cellView = [self createCellLayout:obj]; //这里为什么要用布局视图作为单元格视图,是因为智能边界线只会影响到布局子视图,非布局子视图是没有智能边界线的。
58+
if (idx == 0)
59+
cellView.myWidth = 80;
60+
else
61+
cellView.weight = 1; //我们这里定义第一列的宽度为80,而其他的列宽平均分配。
62+
63+
[tableLayout addSubview:cellView]; //表格布局重写了addSubview,表示总是添加到最后一行上。
64+
}];
65+
66+
67+
NSArray *names = @[@"欧阳大哥",@"周杰",@"{丸の子}",@"小鱼",@"Sarisha゛"];
68+
NSArray *values = @[@"", @"10",@"20"];
69+
70+
//建立10行的数据。
71+
for (int i = 0; i < 10; i++)
72+
{
73+
[tableLayout addRow:40 colSize:MTLSIZE_MATCHPARENT]; //添加新的一行。
74+
75+
for (int j = 0; j < firstRowTitles.count; j++)
76+
{
77+
UIView *cellView = nil;
78+
if (j == 0)
79+
{
80+
cellView = [self createCellLayout:names[arc4random_uniform((uint32_t)names.count)]];
81+
cellView.myWidth = 80;
82+
}
83+
else
84+
{
85+
cellView = [self createCellLayout:values[arc4random_uniform((uint32_t)values.count)]];
86+
cellView.weight = 1;
87+
}
88+
89+
[tableLayout addSubview:cellView];
90+
}
91+
}
92+
93+
//最后一行:
94+
MyLinearLayout *lastRow = [tableLayout addRow:60 colSize:MTLSIZE_MATCHPARENT];
95+
lastRow.notUseIntelligentBorderLine = YES;
96+
lastRow.topBorderLine = [[MyBorderLineDraw alloc] initWithColor:[UIColor greenColor]];
97+
98+
UIView *cellLayout = [self createCellLayout:@"合计:"];
99+
cellLayout.weight = 1; //占用剩余宽度
100+
[tableLayout addSubview:cellLayout];
101+
102+
cellLayout = [self createCellLayout:@"$1234.11"];
103+
cellLayout.myWidth = 100; //固定宽度。
104+
[tableLayout addSubview:cellLayout];
105+
106+
}
107+
108+
109+
- (void)viewDidLoad {
110+
[super viewDidLoad];
111+
// Do any additional setup after loading the view.
112+
113+
}
114+
115+
- (void)didReceiveMemoryWarning {
116+
[super didReceiveMemoryWarning];
117+
// Dispose of any resources that can be recreated.
118+
}
119+
120+
#pragma mark -- Layout Construction
121+
122+
-(MyFrameLayout*)createCellLayout:(NSString*)value
123+
{
124+
MyFrameLayout *cellLayout = [MyFrameLayout new];
125+
126+
UILabel *label = [UILabel new];
127+
label.text = value;
128+
label.adjustsFontSizeToFitWidth = YES;
129+
label.textAlignment = NSTextAlignmentCenter;
130+
label.font = [UIFont systemFontOfSize:14];
131+
label.marginGravity = MyMarginGravity_Fill;
132+
[cellLayout addSubview:label];
133+
134+
return cellLayout;
135+
}
136+
137+
138+
/*
139+
#pragma mark - Navigation
140+
141+
// In a storyboard-based application, you will often want to do a little preparation before navigation
142+
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
143+
// Get the new view controller using [segue destinationViewController].
144+
// Pass the selected object to the new view controller.
145+
}
146+
*/
147+
148+
@end

0 commit comments

Comments
 (0)