├── .gitignore ├── CUSLayout-Prefix.pch ├── CUSLayout.podspec ├── CUSLayout ├── CUSLayout.h ├── algorithm │ ├── CUSFillLayout.h │ ├── CUSFillLayout.m │ ├── CUSGridData.h │ ├── CUSGridData.m │ ├── CUSGridLayout.h │ ├── CUSGridLayout.m │ ├── CUSLinearData.h │ ├── CUSLinearData.m │ ├── CUSLinearLayout.h │ ├── CUSLinearLayout.m │ ├── CUSRowData.h │ ├── CUSRowData.m │ ├── CUSRowLayout.h │ ├── CUSRowLayout.m │ ├── CUSStackLayout.h │ ├── CUSStackLayout.m │ ├── CUSTableData.h │ ├── CUSTableData.m │ ├── CUSTableLayout.h │ └── CUSTableLayout.m ├── core │ ├── CUSLayoutConstant.h │ ├── CUSLayoutData.h │ ├── CUSLayoutData.m │ ├── CUSLayoutFrame.h │ ├── CUSLayoutFrame.m │ ├── CUSLayoutObject+Util.h │ ├── CUSLayoutObject+Util.m │ ├── UIView+CUSLayout.h │ └── UIView+CUSLayout.m ├── extend │ ├── CUSLayoutDesignerView.h │ └── CUSLayoutDesignerView.m └── util │ ├── CUSLayoutUtil.h │ └── CUSLayoutUtil.m ├── CUSLayoutExample.xcodeproj └── project.pbxproj ├── CUSLayoutExample ├── CUSAppDelegate.h ├── CUSAppDelegate.m ├── CUSLayoutExample-Info.plist ├── CUSLayoutExample-Prefix.pch ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── LaunchImage.launchimage │ │ └── Contents.json ├── Resources │ ├── Icon.png │ ├── Icon@2x.png │ └── README.txt ├── controller │ ├── advanced │ │ ├── CUSGridLayoutSampleViewController.h │ │ ├── CUSGridLayoutSampleViewController.m │ │ ├── CUSGridLayoutSampleViewController.xib │ │ ├── CUSRowLayoutSampleViewController.h │ │ ├── CUSRowLayoutSampleViewController.m │ │ ├── CUSRowLayoutSampleViewController.xib │ │ ├── CUSTableLayoutSampleViewController.h │ │ ├── CUSTableLayoutSampleViewController.m │ │ └── CUSTableLayoutSampleViewController.xib │ ├── base │ │ ├── CUSFillLayoutSampleViewController.h │ │ ├── CUSFillLayoutSampleViewController.m │ │ ├── CUSFillLayoutSampleViewController.xib │ │ ├── CUSLinearLayoutSampleViewController.h │ │ ├── CUSLinearLayoutSampleViewController.m │ │ ├── CUSLinearLayoutSampleViewController.xib │ │ ├── CUSStackLayoutSampleViewController.h │ │ ├── CUSStackLayoutSampleViewController.m │ │ └── CUSStackLayoutSampleViewController.xib │ ├── exampleCommon │ │ ├── CUSAboutViewController.h │ │ ├── CUSAboutViewController.m │ │ ├── CUSAboutViewController.xib │ │ ├── CUSLayoutSampleFactory.h │ │ ├── CUSLayoutSampleFactory.m │ │ ├── CUSMainViewController.h │ │ ├── CUSMainViewController.m │ │ ├── CUSViewController.h │ │ └── CUSViewController.m │ ├── other │ │ ├── CUSLayoutManagerSampleViewController.h │ │ ├── CUSLayoutManagerSampleViewController.m │ │ └── CUSLayoutManagerSampleViewController.xib │ └── typical │ │ ├── CUS9GridViewController.h │ │ ├── CUS9GridViewController.m │ │ ├── CUSFlowViewController.h │ │ ├── CUSFlowViewController.m │ │ ├── CUSMultiViewDividedViewController.h │ │ ├── CUSMultiViewDividedViewController.m │ │ ├── CUSPassViewController.h │ │ ├── CUSPassViewController.m │ │ ├── CUSSingleViewFillViewController.h │ │ ├── CUSSingleViewFillViewController.m │ │ ├── CUSThreeViewExtendViewController.h │ │ ├── CUSThreeViewExtendViewController.m │ │ ├── CUSTowViewDividedViewController.h │ │ ├── CUSTowViewDividedViewController.m │ │ ├── CUSTypicalCasesViewController.h │ │ ├── CUSTypicalCasesViewController.m │ │ ├── CUSWaterfallViewController.h │ │ └── CUSWaterfallViewController.m ├── en.lproj │ └── InfoPlist.strings └── main.m ├── CUSLayoutExampleTests ├── CUSLayoutExampleTests-Info.plist ├── CUSLayoutExampleTests.m └── en.lproj │ └── InfoPlist.strings ├── CUSLayoutTests ├── CUSLayoutTests-Info.plist ├── CUSLayoutTests.m └── en.lproj │ └── InfoPlist.strings ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | *.xcworkspace 13 | !default.xcworkspace 14 | xcuserdata 15 | profile 16 | *.moved-aside 17 | DerivedData 18 | .idea/ 19 | -------------------------------------------------------------------------------- /CUSLayout-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #ifdef __OBJC__ 8 | #import 9 | #endif 10 | -------------------------------------------------------------------------------- /CUSLayout.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "CUSLayout" 3 | s.version = "1.1.7" 4 | s.summary = "iOS Auto Layout Manager." 5 | s.homepage = "https://github.com/JJMM/CUSLayout" 6 | s.license = "Apache License, Version 2.0" 7 | s.authors = { "JJMM" => "CUSLayout@163.com" } 8 | s.source = { :git => "https://github.com/JJMM/CUSLayout.git", :tag => "#{s.version}" } 9 | s.frameworks = 'Foundation','UIKit','CoreGraphics' 10 | s.platform = :ios 11 | s.source_files = 'CUSLayout/CUSLayout.h' 12 | s.requires_arc = true 13 | 14 | s.subspec 'core' do |ss| 15 | ss.source_files = 'CUSLayout/core/*' 16 | end 17 | 18 | s.subspec 'algorithm' do |ss| 19 | ss.dependency 'CUSLayout/core' 20 | ss.source_files = 'CUSLayout/algorithm/*' 21 | end 22 | 23 | s.subspec 'extend' do |ss| 24 | ss.dependency 'CUSLayout/core' 25 | ss.dependency 'CUSLayout/algorithm' 26 | ss.source_files = 'CUSLayout/extend/*' 27 | end 28 | 29 | s.subspec 'util' do |ss| 30 | ss.dependency 'CUSLayout/core' 31 | ss.dependency 'CUSLayout/algorithm' 32 | ss.source_files = 'CUSLayout/util/*' 33 | end 34 | end 35 | 36 | -------------------------------------------------------------------------------- /CUSLayout/CUSLayout.h: -------------------------------------------------------------------------------- 1 | /** 2 | @header CUSLayout.h 3 | @abstract Automatic Layout Manager 4 | @discussion please add #import "CUSLayout.h" to pch file 5 | @code 6 | 7 | @link 8 | https://github.com/JJMM/CUSLayout 9 | @version 1.00 2013/4/9 Creation 10 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 11 | */ 12 | 13 | #import "CUSLayoutConstant.h" 14 | #import "UIView+CUSLayout.h" 15 | #import "CUSLayoutFrame.h" 16 | #import "CUSLayoutData.h" 17 | 18 | #import "CUSFillLayout.h" 19 | #import "CUSLinearLayout.h" 20 | #import "CUSLinearData.h" 21 | #import "CUSRowLayout.h" 22 | #import "CUSRowData.h" 23 | #import "CUSTableLayout.h" 24 | #import "CUSTableData.h" 25 | #import "CUSStackLayout.h" 26 | #import "CUSGridLayout.h" 27 | #import "CUSGridData.h" 28 | #import "CUSLayoutUtil.h" 29 | #import "CUSLayoutDesignerView.h" -------------------------------------------------------------------------------- /CUSLayout/algorithm/CUSFillLayout.h: -------------------------------------------------------------------------------- 1 | /** 2 | @header CUSFillLayout.h 3 | @abstract 4 | @code 5 | 6 | @link 7 | https://github.com/JJMM/CUSLayout 8 | @version 1.00 2013/4/9 Creation 9 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 10 | */ 11 | 12 | #import "CUSLayoutFrame.h" 13 | #import "CUSLayoutConstant.h" 14 | 15 | /** 16 | @class CUSFillLayout 17 | @abstract A simple and efficient layout.Fill in all the subview in the parent view. 18 | */ 19 | @interface CUSFillLayout : CUSLayoutFrame 20 | @property (nonatomic,assign) CUSLayoutType type;//Default:CUSLayoutTypeHorizontal 21 | @property (nonatomic,assign) CGFloat spacing; //Default:5 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /CUSLayout/algorithm/CUSFillLayout.m: -------------------------------------------------------------------------------- 1 | /** 2 | @version 1.00 2013/4/9 Creation 3 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 4 | */ 5 | 6 | #import "CUSFillLayout.h" 7 | 8 | @implementation CUSFillLayout 9 | @synthesize type; 10 | @synthesize spacing; 11 | 12 | - (id)init 13 | { 14 | self = [super init]; 15 | if (self) { 16 | [self setMargin:0]; 17 | self.type = CUSLayoutTypeHorizontal; 18 | self.spacing = 5.0; 19 | } 20 | return self; 21 | } 22 | 23 | -(CGSize)computeSize:(UIView *)composite wHint:(CGFloat)wHint hHint:(CGFloat)hHint{ 24 | CGFloat marginWidth = self.marginLeft + self.marginRight; 25 | CGFloat marginHeight = self.marginTop + self.marginBottom; 26 | 27 | if (wHint != CUS_LAY_DEFAULT && hHint != CUS_LAY_DEFAULT) { 28 | return CGSizeMake(wHint, hHint); 29 | } 30 | NSArray *children = [self getUsealbeChildren:composite]; 31 | NSInteger count = [children count]; 32 | if (count == 0) { 33 | return CGSizeMake(wHint != CUS_LAY_DEFAULT ? wHint : 0, 34 | hHint != CUS_LAY_DEFAULT ? hHint : 0); 35 | } else { 36 | NSInteger child_wHint = wHint, child_hHint = hHint; 37 | if (type == CUSLayoutTypeHorizontal && wHint != CUS_LAY_DEFAULT) { 38 | child_wHint = round(MAX(0, 39 | (wHint - (count - 1) * spacing - marginWidth * 2) / count)); 40 | } 41 | if (type == CUSLayoutTypeVertical && hHint != CUS_LAY_DEFAULT) { 42 | child_hHint = round(MAX(0, 43 | (hHint - (count - 1) * spacing - marginHeight * 2) 44 | / count)); 45 | } 46 | CGFloat maxWidth = 0, maxHeight = 0; 47 | for (int i=0; i 9 | @implementation CUSGridData{ 10 | NSInteger defaultWhint, defaultHhint, defaultWidth, defaultHeight; 11 | NSInteger currentWhint, currentHhint, currentWidth, currentHeight; 12 | 13 | } 14 | @synthesize verticalAlignment; 15 | @synthesize horizontalAlignment; 16 | @synthesize horizontalIndent; 17 | @synthesize verticalIndent; 18 | @synthesize horizontalSpan; 19 | @synthesize verticalSpan; 20 | @synthesize widthHint; 21 | @synthesize heightHint; 22 | @synthesize grabExcessHorizontalSpace; 23 | @synthesize grabExcessVerticalSpace; 24 | @synthesize minimumWidth; 25 | @synthesize minimumHeight; 26 | 27 | @synthesize cacheWidth; 28 | @synthesize cacheHeight; 29 | - (id)init 30 | { 31 | self = [super init]; 32 | if (self) { 33 | self.horizontalAlignment = CUSLayoutAlignmentFill; 34 | self.verticalAlignment = CUSLayoutAlignmentFill; 35 | self.horizontalIndent = 0; 36 | self.verticalIndent = 0; 37 | self.horizontalSpan = 1; 38 | self.verticalSpan = 1; 39 | self.widthHint = CUS_LAY_DEFAULT; 40 | self.heightHint = CUS_LAY_DEFAULT; 41 | 42 | self.grabExcessHorizontalSpace = NO; 43 | self.grabExcessVerticalSpace = NO; 44 | self.minimumWidth = 0; 45 | self.minimumHeight = 0; 46 | 47 | self.cacheWidth = -1; 48 | self.cacheHeight = -1; 49 | } 50 | return self; 51 | } 52 | -(void) computeSize:(UIView *)control wHint:(NSInteger)wHint hHint:(NSInteger)hHint flushCache:(BOOL)flushCache { 53 | if (cacheWidth != -1 && cacheHeight != -1) return; 54 | if (wHint == self.widthHint && hHint == self.heightHint) { 55 | if (defaultWidth == -1 || defaultHeight == -1 || wHint != defaultWhint || hHint != defaultHhint) { 56 | CGSize size = [control computeSize:CGSizeMake(wHint, hHint)]; 57 | defaultWhint = wHint; 58 | defaultHhint = hHint; 59 | defaultWidth = size.width; 60 | defaultHeight = size.height; 61 | } 62 | cacheWidth = defaultWidth; 63 | cacheHeight = defaultHeight; 64 | return; 65 | } 66 | if (currentWidth == -1 || currentHeight == -1 || wHint != currentWhint || hHint != currentHhint) { 67 | CGSize size = [control computeSize:CGSizeMake(wHint, hHint)]; 68 | currentWhint = wHint; 69 | currentHhint = hHint; 70 | currentWidth = size.width; 71 | currentHeight = size.height; 72 | } 73 | cacheWidth = currentWidth; 74 | cacheHeight = currentHeight; 75 | } 76 | -(void) flushCache{ 77 | cacheWidth = cacheHeight = -1; 78 | } 79 | 80 | 81 | @end 82 | 83 | @implementation CUSGridData(Factory) 84 | +(CUSGridData *)createWithWidth:(CGFloat)width withHeight:(CGFloat)height{ 85 | CUSGridData *data = [[CUSGridData alloc]init]; 86 | data.widthHint = width; 87 | data.heightHint = height; 88 | return data; 89 | } 90 | +(CUSGridData *)createGrab{ 91 | CUSGridData *data = [[CUSGridData alloc]init]; 92 | data.grabExcessHorizontalSpace = YES; 93 | data.grabExcessVerticalSpace = YES; 94 | return data; 95 | } 96 | @end -------------------------------------------------------------------------------- /CUSLayout/algorithm/CUSGridLayout.h: -------------------------------------------------------------------------------- 1 | /** 2 | @header CUSGridLayout.h 3 | @abstract 4 | @code 5 | 6 | @link 7 | https://github.com/JJMM/CUSLayout 8 | @version 1.00 2013/4/9 Creation 9 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 10 | */ 11 | 12 | #import "CUSLayoutFrame.h" 13 | 14 | /** 15 | @class CUSGridLayout 16 | @abstract 17 | */ 18 | @interface CUSGridLayout : CUSLayoutFrame 19 | @property (nonatomic,assign) NSInteger numColumns;//Default:1 20 | @property (nonatomic,assign) BOOL makeColumnsEqualWidth;//Default:YES 21 | @property (nonatomic,assign) CGFloat horizontalSpacing;//Default:5 22 | @property (nonatomic,assign) CGFloat verticalSpacing;//Default:5 23 | 24 | /** 25 | @abstract init. 26 | @param numColumns 27 | */ 28 | - (id)initWithNumColumns:(NSInteger)numColumns; 29 | @end 30 | -------------------------------------------------------------------------------- /CUSLayout/algorithm/CUSLinearData.h: -------------------------------------------------------------------------------- 1 | /** 2 | @header CUSLinearData.h 3 | @abstract 4 | @code 5 | 6 | @link 7 | https://github.com/JJMM/CUSLayout 8 | @version 1.00 2013/4/9 Creation 9 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 10 | */ 11 | 12 | #import "CUSLayoutData.h" 13 | #import "CUSLayoutConstant.h" 14 | 15 | /** 16 | @class CUSLinearData 17 | @abstract 18 | */ 19 | @interface CUSLinearData : CUSLayoutData 20 | @property (nonatomic,assign) CGFloat width;//Default:CUS_LAY_DEFAULT 21 | @property (nonatomic,assign) CGFloat height;//Default:CUS_LAY_DEFAULT 22 | @property (nonatomic,assign) BOOL fill;//Default:NO 23 | 24 | - (instancetype)initWithWidth:(CGFloat)width; 25 | 26 | - (instancetype)initWithHeight:(CGFloat)height; 27 | 28 | - (instancetype)initWithWidth:(CGFloat)width height:(CGFloat)height; 29 | 30 | - (instancetype)initWithFill:(CGFloat)fill; 31 | @end 32 | 33 | 34 | @interface CUSLinearData(Factory) 35 | 36 | + (CUSLinearData *)createWithWidth:(CGFloat)width; 37 | 38 | + (CUSLinearData *)createWithHeight:(CGFloat)height; 39 | 40 | + (CUSLinearData *)createWithWidth:(CGFloat)width height:(CGFloat)height; 41 | 42 | + (CUSLinearData *)createWithFill:(CGFloat)fill; 43 | @end -------------------------------------------------------------------------------- /CUSLayout/algorithm/CUSLinearData.m: -------------------------------------------------------------------------------- 1 | /** 2 | @version 1.00 2013/4/9 Creation 3 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 4 | */ 5 | 6 | #import "CUSLinearData.h" 7 | 8 | @implementation CUSLinearData 9 | @synthesize width = _width; 10 | @synthesize height = _height; 11 | @synthesize fill = _fill; 12 | - (id)init 13 | { 14 | self = [super init]; 15 | if (self) { 16 | self.width = CUS_LAY_DEFAULT; 17 | self.height = CUS_LAY_DEFAULT; 18 | self.fill = NO; 19 | } 20 | return self; 21 | } 22 | 23 | - (instancetype)initWithWidth:(CGFloat)width 24 | { 25 | self = [self init]; 26 | if (self) { 27 | _width = width; 28 | } 29 | return self; 30 | } 31 | 32 | - (instancetype)initWithHeight:(CGFloat)height 33 | { 34 | self = [self init]; 35 | if (self) { 36 | _height = height; 37 | } 38 | return self; 39 | } 40 | 41 | - (instancetype)initWithWidth:(CGFloat)width height:(CGFloat)height 42 | { 43 | self = [self init]; 44 | if (self) { 45 | _width = width; 46 | _height = height; 47 | } 48 | return self; 49 | } 50 | 51 | - (instancetype)initWithFill:(CGFloat)fill 52 | { 53 | self = [self init]; 54 | if (self) { 55 | _fill = fill; 56 | } 57 | return self; 58 | } 59 | @end 60 | 61 | @implementation CUSLinearData(Factory) 62 | + (CUSLinearData *)createWithWidth:(CGFloat)width 63 | { 64 | return [[CUSLinearData alloc]initWithWidth:width]; 65 | } 66 | 67 | + (CUSLinearData *)createWithHeight:(CGFloat)height 68 | { 69 | return [[CUSLinearData alloc]initWithHeight:height]; 70 | } 71 | 72 | + (CUSLinearData *)createWithWidth:(CGFloat)width height:(CGFloat)height 73 | { 74 | return [[CUSLinearData alloc]initWithWidth:width height:height]; 75 | } 76 | 77 | + (CUSLinearData *)createWithFill:(CGFloat)fill 78 | { 79 | return [[CUSLinearData alloc]initWithFill:fill]; 80 | } 81 | 82 | @end 83 | -------------------------------------------------------------------------------- /CUSLayout/algorithm/CUSLinearLayout.h: -------------------------------------------------------------------------------- 1 | /** 2 | @header CUSLinearLayout.h 3 | @abstract 4 | @code 5 | 6 | @link 7 | https://github.com/JJMM/CUSLayout 8 | @version 1.00 2013/4/9 Creation 9 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 10 | */ 11 | 12 | #import "CUSLayoutFrame.h" 13 | #import "CUSLayoutConstant.h" 14 | 15 | /** 16 | @class CUSLinearLayout 17 | @abstract A simple and efficient layout.Similar to HTML layout or Android LinearLayout. 18 | */ 19 | @interface CUSLinearLayout : CUSLayoutFrame 20 | @property (nonatomic,assign) CUSLayoutType type;//Default:CUSLayoutTypeVertical 21 | @property (nonatomic,assign) CUSLayoutAlignmentType alignment;//Default:CUSLayoutAlignmentFill 22 | @property (nonatomic,assign) CGFloat spacing;//Default:5 23 | @end 24 | -------------------------------------------------------------------------------- /CUSLayout/algorithm/CUSLinearLayout.m: -------------------------------------------------------------------------------- 1 | /** 2 | @version 1.00 2013/4/9 Creation 3 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 4 | */ 5 | 6 | #import "CUSLinearLayout.h" 7 | #import "CUSLinearData.h" 8 | @implementation CUSLinearLayout 9 | @synthesize type; 10 | @synthesize alignment; 11 | @synthesize spacing; 12 | 13 | - (id)init 14 | { 15 | self = [super init]; 16 | if (self) { 17 | [self setMargin:5]; 18 | self.type = CUSLayoutTypeVertical; 19 | self.alignment = CUSLayoutAlignmentFill; 20 | self.spacing = 5; 21 | } 22 | return self; 23 | } 24 | 25 | -(CGSize)computeSize:(UIView *)composite wHint:(CGFloat)wHint hHint:(CGFloat)hHint{ 26 | CGFloat marginWidth = self.marginLeft + self.marginRight; 27 | CGFloat marginHeight = self.marginTop + self.marginBottom; 28 | 29 | if (wHint != CUS_LAY_DEFAULT && hHint != CUS_LAY_DEFAULT) { 30 | return CGSizeMake(wHint, hHint); 31 | } 32 | NSArray *children = [self getUsealbeChildren:composite]; 33 | NSInteger count = [children count]; 34 | if (count == 0) { 35 | return CGSizeMake(wHint != CUS_LAY_DEFAULT ? wHint : 0, 36 | hHint != CUS_LAY_DEFAULT ? hHint : 0); 37 | } else { 38 | CGFloat width = 0, height = 0; 39 | for (int i=0; i 0){ 133 | NSInteger perFillWidth = width/fillControllCounter; 134 | if(perFillWidth<0){ 135 | perFillWidth = 0; 136 | } 137 | //compute fill 138 | for (int i=0; i<[children count]; i++) { 139 | UIView *child = [children objectAtIndex:i]; 140 | if([self isFillControl:child]){ 141 | NSValue *value = [boudns objectAtIndex:i]; 142 | CGRect rect = [value CGRectValue]; 143 | rect.size.width = perFillWidth; 144 | value = [NSValue valueWithCGRect:rect]; 145 | [boudns replaceObjectAtIndex:i withObject:value]; 146 | } 147 | } 148 | } 149 | 150 | 151 | NSInteger startX = areaRect.origin.x; 152 | NSInteger startY = areaRect.origin.y; 153 | //recompute location 154 | for (int i = 0; i<[boudns count]; i++) { 155 | NSValue *value = [boudns objectAtIndex:i]; 156 | CGRect rect = [value CGRectValue]; 157 | rect.origin.x = startX; 158 | startX += rect.size.width + spacing; 159 | 160 | if(self.alignment == CUSLayoutAlignmentLeft){ 161 | rect.origin.y = startY; 162 | }else if(self.alignment == CUSLayoutAlignmentCenter){ 163 | rect.origin.y = startY + (areaRect.size.height - rect.size.height)/2 ; 164 | }else if(self.alignment == CUSLayoutAlignmentRight){ 165 | rect.origin.y = startY + (areaRect.size.height - rect.size.height) ; 166 | }else if(self.alignment == CUSLayoutAlignmentFill){ 167 | rect.origin.y = startY; 168 | } 169 | 170 | value = [NSValue valueWithCGRect:rect]; 171 | [boudns replaceObjectAtIndex:i withObject:value]; 172 | } 173 | return boudns; 174 | } 175 | 176 | -(BOOL)isFillControl:(UIView *)control{ 177 | if(!control){ 178 | return NO; 179 | } 180 | CUSLinearData *data = [self getLayoutDataByControll:control]; 181 | if(data){ 182 | if(data.fill){ 183 | return YES; 184 | } 185 | } 186 | return NO; 187 | } 188 | 189 | -(CGSize)computeChildSizeWithDirection:(UIView *)control wHint:(CGFloat)wHint hHint:(CGFloat)hHint{ 190 | CGSize size = [self computeChildSize:control wHint:wHint hHint:hHint]; 191 | if(self.type != CUSLayoutTypeHorizontal){ 192 | NSInteger t = size.width; 193 | size.width = size.height; 194 | size.height = t; 195 | } 196 | return size; 197 | } 198 | 199 | -(CGSize)computeChildSize:(UIView *)control wHint:(CGFloat)wHint hHint:(CGFloat)hHint{ 200 | CGSize size = CGSizeMake(0, 0); 201 | CUSLinearData *data = [self getLayoutDataByControll:control]; 202 | if (data != nil) { 203 | wHint = data.width; 204 | hHint = data.height; 205 | } 206 | size = [control computeSize:CGSizeMake(wHint, hHint)]; 207 | if (data != nil) { 208 | if(data.width != CUS_LAY_DEFAULT){ 209 | size.width = data.width; 210 | } 211 | if(data.height != CUS_LAY_DEFAULT){ 212 | size.height = data.height; 213 | } 214 | } 215 | return size; 216 | } 217 | -(CUSLinearData *)getLayoutDataByControll:(UIView *)control{ 218 | CUSLayoutData *data = [control getLayoutData]; 219 | if (data) { 220 | if([data isKindOfClass:[CUSLinearData class]]){ 221 | return (CUSLinearData *)data; 222 | } 223 | } 224 | return nil; 225 | } 226 | -(void)setControlsBounds:(NSArray *)children bounds:(NSMutableArray *)bounds{ 227 | for (int i = 0; i < [children count]; i++) { 228 | UIView * control = [children objectAtIndex:i]; 229 | NSValue *listValue = [bounds objectAtIndex:i]; 230 | CGRect rectangle = [listValue CGRectValue]; 231 | [self setControlFrame:control withFrame:rectangle]; 232 | } 233 | }; 234 | @end 235 | -------------------------------------------------------------------------------- /CUSLayout/algorithm/CUSRowData.h: -------------------------------------------------------------------------------- 1 | /** 2 | @header CUSRowData.h 3 | @abstract 4 | @code 5 | 6 | @link 7 | https://github.com/JJMM/CUSLayout 8 | @version 1.00 2013/4/9 Creation 9 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 10 | */ 11 | 12 | #import "CUSLayoutData.h" 13 | #import "CUSLayoutConstant.h" 14 | 15 | /** 16 | @class CUSRowData 17 | @abstract 18 | */ 19 | @interface CUSRowData : CUSLayoutData 20 | @property (nonatomic,assign) CGFloat width;//Default:CUS_LAY_DEFAULT 21 | @property (nonatomic,assign) CGFloat height;//Default:CUS_LAY_DEFAULT 22 | //Dafault:NO If YES The remaining space to the view 23 | @property (nonatomic,assign) BOOL fill;//Dafault:NO 24 | @property (nonatomic,assign) CUSLayoutAlignmentType alignment;//Dafault:CUSLayoutAlignmentFill 25 | 26 | /** 27 | @abstract init. 28 | @param width 29 | @param height 30 | */ 31 | - (id)initWithWidth:(CGFloat)width height:(CGFloat)height; 32 | @end 33 | -------------------------------------------------------------------------------- /CUSLayout/algorithm/CUSRowData.m: -------------------------------------------------------------------------------- 1 | /** 2 | @version 1.00 2013/4/9 Creation 3 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 4 | */ 5 | 6 | #import "CUSRowData.h" 7 | 8 | @implementation CUSRowData 9 | @synthesize width = _width; 10 | @synthesize height = _height; 11 | @synthesize fill; 12 | @synthesize alignment; 13 | 14 | - (id)init 15 | { 16 | self = [super init]; 17 | if (self) { 18 | self.width = CUS_LAY_DEFAULT; 19 | self.height = CUS_LAY_DEFAULT; 20 | self.fill = NO; 21 | self.alignment = CUSLayoutAlignmentFill; 22 | } 23 | return self; 24 | } 25 | 26 | - (id)initWithWidth:(CGFloat)width height:(CGFloat)height{ 27 | self = [super init]; 28 | if (self) { 29 | self.width = width; 30 | self.height = height; 31 | } 32 | return self; 33 | } 34 | @end 35 | -------------------------------------------------------------------------------- /CUSLayout/algorithm/CUSRowLayout.h: -------------------------------------------------------------------------------- 1 | /** 2 | @header CUSRowLayout.h 3 | @abstract 4 | @code 5 | 6 | @link 7 | https://github.com/JJMM/CUSLayout 8 | @version 1.00 2013/4/9 Creation 9 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 10 | */ 11 | 12 | #import "CUSLayoutFrame.h" 13 | #import "CUSLayoutConstant.h" 14 | 15 | /** 16 | @class CUSLinearLayout 17 | @abstract The subview in the parent view layout to a row or column 18 | */ 19 | @interface CUSRowLayout : CUSLayoutFrame 20 | @property (nonatomic,assign) CUSLayoutType type;//Default:CUSLayoutTypeHorizontal 21 | @property (nonatomic,assign) CGFloat spacing;//Default:5 22 | 23 | //If NO layout in one line, elsewise layout in mutil lines 24 | @property (nonatomic,assign) BOOL wrap;//Default:YES 25 | 26 | //It work on wrap = NO.All subviews fill the remaining space to the view. 27 | @property (nonatomic,assign) BOOL fill;//Default:NO 28 | 29 | //Not implemented 30 | @property (nonatomic,assign) BOOL pack;//Default:YES 31 | 32 | //Spacing to divide, spacing control, make the control looks uniform 33 | @property (nonatomic,assign) BOOL justify;//Default:NO 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /CUSLayout/algorithm/CUSRowLayout.m: -------------------------------------------------------------------------------- 1 | /** 2 | @version 1.00 2013/4/9 Creation 3 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 4 | */ 5 | 6 | #import "CUSRowLayout.h" 7 | #import "CUSRowData.h" 8 | #import "CUSLayoutObject+Util.h" 9 | @implementation CUSRowLayout 10 | @synthesize type; 11 | @synthesize spacing; 12 | @synthesize wrap; 13 | @synthesize fill; 14 | @synthesize pack; 15 | @synthesize justify; 16 | 17 | 18 | - (id)init 19 | { 20 | self = [super init]; 21 | if (self) { 22 | [self setMargin:5]; 23 | self.type = CUSLayoutTypeHorizontal; 24 | self.spacing = 5; 25 | self.wrap = YES; 26 | self.pack = YES; 27 | self.justify = NO; 28 | } 29 | return self; 30 | } 31 | 32 | -(void)layout:(UIView *)composite{ 33 | BOOL flushCache = NO; 34 | CGRect rect = [self computeUseSize:composite flushCache:flushCache]; 35 | NSArray *children = [self getUsealbeChildren:composite]; 36 | NSMutableArray *bounds = [NSMutableArray array]; 37 | // fill = true, no warp 38 | if (self.fill) { 39 | [self processFill:children bounds:bounds rect:rect flushCache:flushCache]; 40 | } else { 41 | if (self.wrap) { 42 | [self processWrap:children bounds:bounds rect:rect flushCache:flushCache]; 43 | } else { 44 | [self proessNormal:children bounds:bounds rect:rect flushCache:flushCache]; 45 | } 46 | } 47 | [self setControlsBounds:children bounds:bounds]; 48 | } 49 | 50 | -(CGSize)computeSize:(UIView *)composite wHint:(CGFloat)wHint hHint:(CGFloat)hHint{ 51 | NSArray *children = [self getUsealbeChildren:composite]; 52 | NSMutableArray *bounds = [NSMutableArray array]; 53 | BOOL flushCache = NO; 54 | 55 | CGSize size; 56 | if (wHint != CUS_LAY_DEFAULT && hHint != CUS_LAY_DEFAULT) { 57 | size = CGSizeMake(wHint, hHint); 58 | } else { 59 | CGRect rect = CGRectMake(0, 0, wHint, hHint); 60 | if (wHint != CUS_LAY_DEFAULT) { 61 | rect.size.width -= self.marginLeft + self.marginRight; 62 | } 63 | if (hHint != CUS_LAY_DEFAULT) { 64 | rect.size.height -= self.marginTop + self.marginBottom; 65 | } 66 | if (self.fill) { 67 | size = [self processFill:children bounds:bounds rect:rect flushCache:flushCache]; 68 | } else { 69 | if (self.wrap) { 70 | size = [self processWrap:children bounds:bounds rect:rect flushCache:flushCache]; 71 | } else { 72 | size = [self proessNormal:children bounds:bounds rect:rect flushCache:flushCache]; 73 | } 74 | } 75 | if (wHint == CUS_LAY_DEFAULT) { 76 | size.width += self.marginLeft + self.marginRight; 77 | } 78 | if (hHint == CUS_LAY_DEFAULT) { 79 | size.height += self.marginTop + self.marginBottom; 80 | } 81 | } 82 | return size; 83 | }; 84 | 85 | 86 | 87 | -(BOOL)flushCache:(UIView *)control{ 88 | return true; 89 | }; 90 | 91 | 92 | -(CGRect)computeUseSize:(UIView *)composite flushCache:(BOOL)flushCache{ 93 | CGRect clientArea = [composite getClientArea]; 94 | clientArea.origin.x += self.marginLeft; 95 | clientArea.origin.y += self.marginTop; 96 | clientArea.size.width -= self.marginLeft + self.marginRight; 97 | clientArea.size.height -= self.marginTop + self.marginBottom; 98 | return clientArea; 99 | }; 100 | 101 | -(CGSize)processFill:(NSArray *)children bounds:(NSMutableArray *)bounds rect:(CGRect)rect flushCache:(BOOL)flushCache{ 102 | NSMutableArray *firstList = [NSMutableArray array]; 103 | [bounds addObject:firstList]; 104 | CGSize preferSize = CGSizeMake(0, 0); 105 | 106 | CGRect all = CGRectMake(rect.origin.x, rect.origin.y, 0, 0); 107 | CGSize packSize = [self getPackSize:children flushCache:flushCache]; 108 | for (int i = 0; i < [children count]; i++) { 109 | UIView *control = [children objectAtIndex:i]; 110 | CGPoint location = CGPointMake(all.origin.x, all.origin.y); 111 | CGSize size = [self computeSize2:control flushCache:flushCache packSize:packSize]; 112 | if (self.type == CUSLayoutTypeHorizontal) { 113 | size.height = rect.size.height; 114 | [firstList addRect:CGRectMake(location.x, location.y, size.width,size.height)]; 115 | [firstList addRect:CGRectMake(0,0,0,0)]; 116 | 117 | all.origin.x += size.width + self.spacing; 118 | 119 | preferSize.width = MAX(preferSize.width, location.x + size.width); 120 | preferSize.height = MAX(preferSize.height, location.y + size.height); 121 | } else { 122 | size.width = rect.size.width; 123 | [firstList addRect:CGRectMake(location.x, location.y, size.width,size.height)]; 124 | all.origin.y += size.height + self.spacing; 125 | preferSize.width = MAX(preferSize.width, location.x + size.width); 126 | preferSize.height = MAX(preferSize.height, location.y + size.height); 127 | } 128 | } 129 | [self processJustify:bounds rectAll:rect]; 130 | return preferSize; 131 | }; 132 | 133 | -(CGSize)processWrap:(NSArray *)children bounds:(NSMutableArray *)bounds rect:(CGRect)rect flushCache:(BOOL)flushCache{ 134 | NSMutableArray *thisList = [NSMutableArray array]; 135 | [bounds addObject:thisList]; 136 | CGSize preferSize = CGSizeMake(0, 0); 137 | 138 | CGRect all = CGRectMake(rect.origin.x, rect.origin.y, 0, 0); 139 | CGSize packSize = [self getPackSize:children flushCache:flushCache]; 140 | for (int i = 0; i < [children count]; i++) { 141 | UIView *control = [children objectAtIndex:i]; 142 | CGPoint location = CGPointMake(all.origin.x, all.origin.y); 143 | CGSize size = [self computeSize2:control flushCache:flushCache packSize:packSize]; 144 | 145 | if (self.type == CUSLayoutTypeHorizontal) { 146 | all.size.height = MAX(all.size.height, size.height); 147 | 148 | if (rect.size.width > 0 && location.x + size.width > rect.origin.x + rect.size.width) { 149 | all.origin.x = rect.origin.x; 150 | all.origin.y += all.size.height + self.spacing; 151 | location.x = all.origin.x; 152 | location.y = all.origin.y; 153 | 154 | thisList = [NSMutableArray array]; 155 | [bounds addObject:thisList]; 156 | } 157 | 158 | [thisList addRect:CGRectMake(location.x, location.y, size.width,size.height)]; 159 | 160 | all.origin.x += size.width + self.spacing; 161 | preferSize.width = MAX(preferSize.width, location.x + size.width); 162 | preferSize.height = MAX(preferSize.height, location.y + size.height); 163 | } else { 164 | all.size.width = MAX(all.size.width, size.width); 165 | 166 | if (rect.size.height > 0 && location.y + size.height > rect.origin.y + rect.size.height) { 167 | all.origin.x += all.size.width + self.spacing; 168 | all.origin.y = rect.origin.y; 169 | location.x = all.origin.x; 170 | location.y = all.origin.y; 171 | 172 | thisList = [NSMutableArray array]; 173 | [bounds addObject:thisList]; 174 | } 175 | 176 | [thisList addRect:CGRectMake(location.x, location.y, size.width,size.height)]; 177 | 178 | all.origin.y += size.height + self.spacing; 179 | preferSize.width = MAX(preferSize.width, location.x + size.width); 180 | preferSize.height = MAX(preferSize.height, location.y + size.height); 181 | } 182 | } 183 | [self processJustify:bounds rectAll:rect]; 184 | return preferSize; 185 | }; 186 | 187 | -(CGSize)proessNormal:(NSArray *)children bounds:(NSMutableArray *)bounds rect:(CGRect)rect flushCache:(BOOL)flushCache{ 188 | NSMutableArray *firstList = [NSMutableArray array]; 189 | [bounds addObject:firstList]; 190 | CGSize preferSize = CGSizeMake(0, 0); 191 | 192 | CGRect all = CGRectMake(rect.origin.x, rect.origin.y, 0, 0); 193 | CGSize packSize = [self getPackSize:children flushCache:flushCache]; 194 | 195 | for (int i = 0; i < [children count]; i++) { 196 | UIView *control = [children objectAtIndex:i]; 197 | CGPoint location = CGPointMake(all.origin.x, all.origin.y); 198 | CGSize size = [self computeSize2:control flushCache:flushCache packSize:packSize]; 199 | 200 | [firstList addRect:CGRectMake(location.x, location.y, size.width,size.height)]; 201 | if (self.type == CUSLayoutTypeHorizontal) { 202 | all.origin.x += size.width; 203 | all.size.height = MAX(all.size.height, size.height); 204 | preferSize.width =MAX(preferSize.width, location.x + size.width); 205 | preferSize.height = MAX(preferSize.height, location.y + size.height); 206 | all.origin.x += self.spacing; 207 | } else { 208 | all.origin.y += size.height + self.spacing; 209 | all.size.width = MAX(all.size.width, size.width); 210 | preferSize.width = MAX(preferSize.width, location.x + size.width); 211 | preferSize.height = MAX(preferSize.height, location.y + size.height); 212 | } 213 | } 214 | if (self.justify && [children count] > 0) { 215 | [self processJustify:bounds rectAll:rect]; 216 | } 217 | return preferSize; 218 | }; 219 | /** 220 | * get the size of view 221 | * 222 | * @param children 223 | * @param flushCache 224 | * @return 225 | */ 226 | -(CGSize)getPackSize:(NSArray *)children flushCache:(BOOL)flushCache{ 227 | CGSize packSize = CGSizeMake(CUS_LAY_EMPTY, CUS_LAY_EMPTY); 228 | if (!self.pack) { 229 | packSize.width = 0; 230 | packSize.height = 0; 231 | for (int i = 0; i < [children count]; i++) { 232 | UIView *control = [children objectAtIndex:i]; 233 | CGSize size = [self computeSize1:control flushCache:flushCache]; 234 | packSize.width = MAX(packSize.width, size.width); 235 | packSize.height = MAX(packSize.height, size.height); 236 | } 237 | } 238 | return packSize; 239 | }; 240 | /** 241 | * reset the size on justify 242 | * 243 | * @param bounds 244 | * @param rectAll 245 | */ 246 | -(void)processJustify:(NSMutableArray *)bounds rectAll:(CGRect)rectAll{ 247 | if (!self.justify) { 248 | return; 249 | } 250 | if (!bounds || [bounds count] <= 0) { 251 | return; 252 | } 253 | for (int i = 0; i < [bounds count]; i++) { 254 | NSMutableArray *list = [bounds objectAtIndex:i]; 255 | NSInteger listLength = [list count]; 256 | if (listLength < 1) { 257 | continue; 258 | } 259 | NSInteger remain = 0; 260 | CGRect rectValue = [list CGRectAtIndex:listLength - 1]; 261 | if (self.type == CUSLayoutTypeHorizontal) { 262 | remain = rectAll.size.width - (rectValue.origin.x + rectValue.size.width); 263 | } else { 264 | remain = rectAll.size.height - (rectValue.origin.y + rectValue.size.height); 265 | } 266 | if (remain > 1) { 267 | NSInteger spare = remain / (listLength + 1); 268 | NSInteger addNow = 0; 269 | for (int j = 0; j < listLength; j++) { 270 | CGRect rectangle = [list CGRectAtIndex:j]; 271 | 272 | addNow += ceil(spare); 273 | if (addNow > remain) { 274 | break; 275 | } 276 | if (self.type == CUSLayoutTypeHorizontal) { 277 | rectangle.origin.x += addNow; 278 | } else { 279 | rectangle.origin.y += addNow; 280 | } 281 | [list replaceRectAtIndex:j withRect:rectangle]; 282 | } 283 | } 284 | } 285 | }; 286 | 287 | -(void)setControlsBounds:(NSArray *)children bounds:(NSMutableArray *)bounds{ 288 | NSInteger index = 0; 289 | for (int i = 0; i < [bounds count]; i++) { 290 | NSMutableArray *list = [bounds objectAtIndex:i]; 291 | NSInteger listLength = [list count]; 292 | NSInteger max = 0; 293 | if (self.type == CUSLayoutTypeHorizontal) { 294 | for (int j = 0; j < listLength; j++) { 295 | CGRect rectangle = [list CGRectAtIndex:j]; 296 | max = MAX(max, rectangle.size.height); 297 | } 298 | for (int j = 0; j < listLength; j++) { 299 | CGRect rectangle = [list CGRectAtIndex:j]; 300 | UIView * control = [children objectAtIndex:index++]; 301 | CUSRowData *data = [self getLayoutDataByControll:control]; 302 | 303 | if (data != nil && data.alignment != CUSLayoutAlignmentLeft) { 304 | if (data.alignment == CUSLayoutAlignmentCenter) { 305 | [self setControlFrame:control withFrame:CGRectMake(rectangle.origin.x, rectangle.origin.y + (max - rectangle.size.height) / 2, 306 | rectangle.size.width, rectangle.size.height)]; 307 | } else if (data.alignment == CUSLayoutAlignmentRight) { 308 | [self setControlFrame:control withFrame:CGRectMake(rectangle.origin.x, rectangle.origin.y + max 309 | - rectangle.size.height, rectangle.size.width, 310 | rectangle.size.height)]; 311 | } else if (data.alignment == CUSLayoutAlignmentFill) { 312 | [self setControlFrame:control withFrame:CGRectMake(rectangle.origin.x, rectangle.origin.y, 313 | rectangle.size.width, max)]; 314 | } 315 | } else { 316 | [self setControlFrame:control withFrame:rectangle]; 317 | } 318 | } 319 | } else if (self.type == CUSLayoutTypeVertical) { 320 | for (int j = 0; j < listLength; j++) { 321 | CGRect rectangle = [list CGRectAtIndex:j]; 322 | max = MAX(max, rectangle.size.width); 323 | } 324 | for (int j = 0; j < listLength; j++) { 325 | CGRect rectangle = [list CGRectAtIndex:j]; 326 | UIView * control = [children objectAtIndex:index++]; 327 | CUSRowData *data = [self getLayoutDataByControll:control]; 328 | 329 | if (data != nil && data.alignment != CUSLayoutAlignmentLeft) { 330 | if (data.alignment == CUSLayoutAlignmentCenter) { 331 | [self setControlFrame:control withFrame:CGRectMake(rectangle.origin.x + (max - rectangle.size.width) 332 | / 2, rectangle.origin.y, rectangle.size.width, 333 | rectangle.size.height)]; 334 | 335 | } else if (data.alignment == CUSLayoutAlignmentRight) { 336 | [self setControlFrame:control withFrame:CGRectMake(rectangle.origin.x + max - rectangle.size.width, 337 | rectangle.origin.y, rectangle.size.width, rectangle.size.height)]; 338 | 339 | } else if (data.alignment == CUSLayoutAlignmentFill) { 340 | [self setControlFrame:control withFrame:CGRectMake(rectangle.origin.x, rectangle.origin.y, max, 341 | rectangle.size.height)]; 342 | } 343 | } else { 344 | [self setControlFrame:control withFrame:rectangle]; 345 | } 346 | } 347 | } 348 | } 349 | }; 350 | 351 | -(CGSize)computeSize1:(UIView *)control flushCache:(BOOL)flushCache{ 352 | int wHint = CUS_LAY_DEFAULT, hHint = CUS_LAY_DEFAULT; 353 | CGSize size = CGSizeMake(0, 0); 354 | CUSRowData *data = [self getLayoutDataByControll:control]; 355 | if (data != nil) { 356 | wHint = data.width; 357 | hHint = data.height; 358 | } 359 | size = [control computeSize:CGSizeMake(wHint, hHint)]; 360 | 361 | if (data != nil) { 362 | if(data.width != CUS_LAY_DEFAULT){ 363 | size.width = data.width; 364 | } 365 | if(data.height != CUS_LAY_DEFAULT){ 366 | size.height = data.height; 367 | } 368 | } 369 | 370 | return size; 371 | } 372 | 373 | -(CUSRowData *)getLayoutDataByControll:(UIView *)control{ 374 | CUSLayoutData *data = [control getLayoutData]; 375 | if (data) { 376 | if([data isKindOfClass:[CUSRowData class]]){ 377 | return (CUSRowData *)data; 378 | } 379 | } 380 | return nil; 381 | } 382 | 383 | -(CGSize)computeSize2:(UIView *)control flushCache:(BOOL)flushCache packSize:(CGSize)packSize{ 384 | if(packSize.width == CUS_LAY_EMPTY &&packSize.height == CUS_LAY_EMPTY){ 385 | return [self computeSize1:control flushCache:flushCache]; 386 | }else{ 387 | return CGSizeMake(packSize.width, packSize.height); 388 | } 389 | }; 390 | 391 | @end 392 | -------------------------------------------------------------------------------- /CUSLayout/algorithm/CUSStackLayout.h: -------------------------------------------------------------------------------- 1 | /** 2 | @header CUSStackLayout.h 3 | @abstract 4 | @code 5 | 6 | @link 7 | https://github.com/JJMM/CUSLayout 8 | @version 1.00 2013/4/9 Creation 9 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 10 | */ 11 | 12 | #import "CUSLayoutFrame.h" 13 | #import "CUSLayoutConstant.h" 14 | 15 | /** 16 | @class CUSStackLayout 17 | @abstract Full screen display a view from subviews. 18 | */ 19 | @interface CUSStackLayout : CUSLayoutFrame 20 | 21 | //The index of view.If "CUSLayoutData.exclude = YES;",it do not need to count. 22 | @property (nonatomic,assign) NSInteger showViewIndex; 23 | 24 | //Default:YES.If NO,through the current view, show background view. 25 | @property (nonatomic,assign) BOOL hideOther; 26 | @end 27 | -------------------------------------------------------------------------------- /CUSLayout/algorithm/CUSStackLayout.m: -------------------------------------------------------------------------------- 1 | /** 2 | @version 1.00 2013/4/9 Creation 3 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 4 | */ 5 | 6 | #import "CUSStackLayout.h" 7 | 8 | @implementation CUSStackLayout 9 | @synthesize showViewIndex; 10 | @synthesize hideOther; 11 | - (instancetype)init 12 | { 13 | self = [super init]; 14 | if (self) { 15 | self.hideOther = YES; 16 | } 17 | return self; 18 | } 19 | - (id)initWithIndex:(NSInteger)index 20 | { 21 | self = [super init]; 22 | if (self) { 23 | self.showViewIndex = index; 24 | self.hideOther = YES; 25 | } 26 | return self; 27 | } 28 | 29 | -(CGSize)computeSize:(UIView *)composite wHint:(CGFloat)wHint hHint:(CGFloat)hHint{ 30 | CGFloat marginWidth = self.marginLeft + self.marginRight; 31 | CGFloat marginHeight = self.marginTop + self.marginBottom; 32 | 33 | if (wHint != CUS_LAY_DEFAULT && hHint != CUS_LAY_DEFAULT) { 34 | return CGSizeMake(wHint, hHint); 35 | } 36 | NSArray *children = [self getUsealbeChildren:composite]; 37 | NSInteger count = [children count]; 38 | if (count == 0) { 39 | return CGSizeMake(wHint != CUS_LAY_DEFAULT ? wHint : 0, 40 | hHint != CUS_LAY_DEFAULT ? hHint : 0); 41 | } else { 42 | CGFloat maxWidth = 0, maxHeight = 0; 43 | for (int i=0; i= [children count]){ 74 | return; 75 | } 76 | for (int i = 0; i < [children count];i++) { 77 | UIView *child = [children objectAtIndex:i]; 78 | CGRect childFrame = child.frame; 79 | if(childFrame.origin.x != x || childFrame.origin.y != y || childFrame.size.width != width || childFrame.size.height != height){ 80 | [self setControlFrame:child withFrame:CGRectMake(x, y, width, height)]; 81 | } 82 | if(i == showViewIndex){ 83 | child.hidden = NO; 84 | }else{ 85 | if (self.hideOther) { 86 | child.hidden = YES; 87 | }else{ 88 | child.hidden = NO; 89 | } 90 | } 91 | } 92 | } 93 | -(CGSize)computeChildSize:(UIView *)control wHint:(int)wHint hHint:(int)hHint{ 94 | CGSize size = [control computeSize:CGSizeMake(wHint, hHint)]; 95 | return size; 96 | }; 97 | @end 98 | -------------------------------------------------------------------------------- /CUSLayout/algorithm/CUSTableData.h: -------------------------------------------------------------------------------- 1 | /** 2 | @header CUSTableData.h 3 | @abstract 4 | @code 5 | 6 | @link 7 | https://github.com/JJMM/CUSLayout 8 | @version 1.00 2013/4/9 Creation 9 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 10 | */ 11 | 12 | #import "CUSLayoutData.h" 13 | #import "CUSLayoutConstant.h" 14 | 15 | /** 16 | @class CUSValue 17 | @code 18 | [CUSValue initWithFloat:100]; 19 | [CUSValue valueWithPercent:0.25]; 20 | @abstract const object.Renew an object when you want to changing the value 21 | */ 22 | @interface CUSValue : NSObject{ 23 | CUSLayoutDataType dataType; 24 | CGFloat value; 25 | } 26 | 27 | /** 28 | @abstract init. 29 | @param floatValue (1 , ∞). Set value type to CUSLayoutDataTypeFloat. 30 | */ 31 | - (id)initWithFloat:(CGFloat)floatValue; 32 | 33 | /** 34 | @abstract init. 35 | @param percentValue (0 ,1]. Set value type to CUSLayoutDataTypePercent. 36 | */ 37 | - (id)initWithPercent:(CGFloat)percentValue; 38 | 39 | -(CUSLayoutDataType)getDataType; 40 | -(CGFloat)getValue; 41 | 42 | + (CUSValue *)valueWithFloat:(float)floatValue; 43 | + (CUSValue *)valueWithPercent:(float)percentValue; 44 | + (CUSValue *)valueWithDefault; 45 | + (CUSValue *)shareValue; 46 | 47 | @end 48 | 49 | /** 50 | @class CUSTableData 51 | @abstract 52 | */ 53 | @interface CUSTableData : CUSLayoutData 54 | @property (nonatomic,strong) CUSValue *width;//Default:[CUSValue shareValue] 55 | @property (nonatomic,strong) CUSValue *height;//Default:[CUSValue shareValue] 56 | @property (nonatomic,assign) CGFloat horizontalIndent;//Default:0 57 | @property (nonatomic,assign) CGFloat verticalIndent;//Default:0 58 | 59 | @property (nonatomic,assign) CUSLayoutAlignmentType horizontalAlignment;//Default:CUSLayoutAlignmentFill 60 | @property (nonatomic,assign) CUSLayoutAlignmentType verticalAlignment;//Default:CUSLayoutAlignmentFill 61 | 62 | @end 63 | 64 | 65 | -------------------------------------------------------------------------------- /CUSLayout/algorithm/CUSTableData.m: -------------------------------------------------------------------------------- 1 | /** 2 | @version 1.00 2013/4/9 Creation 3 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 4 | */ 5 | 6 | #import "CUSTableData.h" 7 | 8 | 9 | static CUSValue* CUSValueInstance; 10 | @implementation CUSValue 11 | - (id)init 12 | { 13 | self = [super init]; 14 | if (self) { 15 | dataType = CUSLayoutDataTypeDefault; 16 | value = CUS_LAY_DEFAULT; 17 | } 18 | return self; 19 | } 20 | - (id)initWithFloat:(CGFloat)floatValue{ 21 | self = [super init]; 22 | if (self) { 23 | dataType = CUSLayoutDataTypeFloat; 24 | value = floatValue; 25 | } 26 | return self; 27 | } 28 | 29 | - (id)initWithPercent:(CGFloat)percentValue{ 30 | self = [super init]; 31 | if (self) { 32 | dataType = CUSLayoutDataTypePercent; 33 | value = percentValue; 34 | } 35 | return self; 36 | } 37 | -(CUSLayoutDataType)getDataType{ 38 | return dataType; 39 | } 40 | -(CGFloat)getValue{ 41 | return value; 42 | } 43 | 44 | + (CUSValue *)valueWithFloat:(float)floatValue{ 45 | return [[CUSValue alloc]initWithFloat:floatValue]; 46 | } 47 | + (CUSValue *)valueWithPercent:(float)percentValue{ 48 | return [[CUSValue alloc]initWithPercent:percentValue]; 49 | } 50 | + (CUSValue *)valueWithDefault{ 51 | return CUSValueInstance; 52 | } 53 | 54 | -(NSString *)description{ 55 | NSString *typeStr = nil; 56 | if([self getDataType] == CUSLayoutDataTypeFloat){ 57 | typeStr = @"Float"; 58 | }else if([self getDataType] == CUSLayoutDataTypePercent){ 59 | typeStr = @"Percent"; 60 | }else{ 61 | typeStr = @"Default"; 62 | } 63 | 64 | NSString *str = [NSString stringWithFormat:@"CUSValue:%@ %f",typeStr,value]; 65 | return str; 66 | } 67 | 68 | + (CUSValue *)shareValue{ 69 | if (!CUSValueInstance) { 70 | CUSValueInstance = [[CUSValue alloc]init]; 71 | } 72 | return CUSValueInstance; 73 | } 74 | 75 | @end 76 | 77 | @implementation CUSTableData 78 | @synthesize width; 79 | @synthesize height; 80 | @synthesize horizontalIndent; 81 | @synthesize verticalIndent; 82 | @synthesize horizontalAlignment; 83 | @synthesize verticalAlignment; 84 | 85 | - (id)init 86 | { 87 | self = [super init]; 88 | if (self) { 89 | self.width = [CUSValue shareValue]; 90 | self.height = [CUSValue shareValue]; 91 | self.horizontalIndent = 0.0; 92 | self.verticalIndent = 0.0; 93 | self.horizontalAlignment = CUSLayoutAlignmentFill; 94 | self.verticalAlignment = CUSLayoutAlignmentFill; 95 | } 96 | return self; 97 | } 98 | 99 | - (id)init:(CUSValue *)width_ height:(CUSValue *)height_{ 100 | self = [self init]; 101 | if (self) { 102 | width = width_; 103 | height = height_; 104 | } 105 | return self; 106 | } 107 | 108 | @end -------------------------------------------------------------------------------- /CUSLayout/algorithm/CUSTableLayout.h: -------------------------------------------------------------------------------- 1 | /** 2 | @header CUSTableLayout.h 3 | @abstract 4 | @code 5 | 6 | @link 7 | https://github.com/JJMM/CUSLayout 8 | @version 1.00 2013/4/9 Creation 9 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 10 | */ 11 | 12 | #import "CUSLayoutFrame.h" 13 | #import "CUSLayoutConstant.h" 14 | 15 | /** 16 | @class CUSTableLayout 17 | @abstract HTML Table Layout 18 | */ 19 | @interface CUSTableLayout : CUSLayoutFrame 20 | @property (nonatomic,assign) BOOL pixelFirst;//Default:5 21 | @property (nonatomic,assign) CGFloat spacing;//Default:5 22 | 23 | /** 24 | * @abstract init 25 | * @param columnWiths 26 | * @param rowHeights 27 | */ 28 | - (id)initWithcolumns:(NSArray *)columnWiths rows:(NSArray *)rowHeights; 29 | 30 | /** 31 | * @abstract merge 32 | * @param column 33 | * @param row 34 | * @param colspan 35 | * @param rowspan 36 | */ 37 | -(void) merge:(NSInteger)column row:(NSInteger)row colspan:(NSInteger) colspan rowspan:(NSInteger) rowspan; 38 | 39 | /** 40 | * @abstract unmerge 41 | * @param column 42 | * @param row 43 | */ 44 | -(void)unmerge:(NSInteger)column row:(NSInteger)row; 45 | 46 | /** 47 | * @abstract 48 | * @result NSInteger 49 | */ 50 | -(NSInteger)getColumnCount; 51 | 52 | /** 53 | * @abstract 54 | * @result NSInteger 55 | */ 56 | -(NSInteger)getRowCount; 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /CUSLayout/core/CUSLayoutConstant.h: -------------------------------------------------------------------------------- 1 | /** 2 | @header CUSLayoutConstant.h 3 | @abstract Constant:CUSLayoutType,CUSLayoutAlignmentType,CUSLayoutDataType 4 | @code 5 | use CUSLayout 6 | @link 7 | https://github.com/JJMM/CUSLayout 8 | @version 1.00 2013/4/9 Creation 9 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 10 | */ 11 | 12 | #import 13 | #import 14 | /** 15 | @enum CUSLayoutType 16 | @abstract Layout direction.Used it in LayoutFrame. 17 | */ 18 | typedef enum { 19 | CUSLayoutTypeHorizontal, 20 | CUSLayoutTypeVertical 21 | }CUSLayoutType; 22 | 23 | /** 24 | @enum CUSLayoutAlignmentType 25 | @abstract Layout alignment position.Used it in LayoutData. 26 | */ 27 | typedef enum { 28 | CUSLayoutAlignmentLeft, 29 | CUSLayoutAlignmentCenter, 30 | CUSLayoutAlignmentRight, 31 | CUSLayoutAlignmentFill 32 | }CUSLayoutAlignmentType; 33 | 34 | /** 35 | @enum CUSLayoutDataType 36 | @abstract Data value type.It's not the type of the LayoutData object. 37 | */ 38 | typedef enum { 39 | CUSLayoutDataTypeFloat, 40 | CUSLayoutDataTypePercent, 41 | CUSLayoutDataTypeDefault 42 | }CUSLayoutDataType; 43 | 44 | #define CUSLAYOUT ([CUSLayoutUtil getShareInstance]) 45 | //#define CUS_LAYOUT ([CUSLayoutUtil getShareInstance]) 46 | #define CUS_LAY_DEFAULT (-1) 47 | #define CUS_LAY_EMPTY (-999999) 48 | 49 | -------------------------------------------------------------------------------- /CUSLayout/core/CUSLayoutData.h: -------------------------------------------------------------------------------- 1 | /** 2 | @header CUSLayoutData.h 3 | @abstract 4 | @code 5 | 6 | @link 7 | https://github.com/JJMM/CUSLayout 8 | @version 1.00 2013/4/9 Creation 9 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 10 | */ 11 | #import 12 | #import 13 | 14 | /** 15 | @class CUSLayoutData 16 | @abstract 17 | The layou helper data.Use it with LayoutFrame. 18 | Precise control the subview in view. 19 | */ 20 | @interface CUSLayoutData : NSObject 21 | 22 | //ignore If YES - the parent view will ignore the subview. 23 | @property (nonatomic,assign) BOOL exclude;//ignore 24 | @end 25 | -------------------------------------------------------------------------------- /CUSLayout/core/CUSLayoutData.m: -------------------------------------------------------------------------------- 1 | /** 2 | @version 1.00 2013/4/9 Creation 3 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 4 | */ 5 | 6 | #import "CUSLayoutData.h" 7 | 8 | @implementation CUSLayoutData 9 | @synthesize exclude; 10 | @end 11 | -------------------------------------------------------------------------------- /CUSLayout/core/CUSLayoutFrame.h: -------------------------------------------------------------------------------- 1 | /** 2 | @header CUSLayoutFrame.h 3 | @abstract 4 | @code 5 | 6 | @link 7 | https://github.com/JJMM/CUSLayout 8 | @version 1.00 2013/4/9 Creation 9 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 10 | */ 11 | 12 | #import 13 | #import 14 | #import "UIView+CUSLayout.h" 15 | /** 16 | @class CUSLayoutFrame 17 | @abstract 18 | The base object of Layout define. 19 | */ 20 | @interface CUSLayoutFrame : NSObject 21 | @property (nonatomic,assign) CGFloat marginLeft; 22 | @property (nonatomic,assign) CGFloat marginTop; 23 | @property (nonatomic,assign) CGFloat marginRight; 24 | @property (nonatomic,assign) CGFloat marginBottom; 25 | 26 | /** 27 | @abstract set marginLeft,marginTop,marginRight,marginBottom 28 | @param margin 29 | */ 30 | -(void)setMargin:(CGFloat)margin; 31 | 32 | /** 33 | @abstract set marginLeft and marginRight 34 | @param margin 35 | */ 36 | -(void)setMarginWidth:(CGFloat)margin; 37 | 38 | /** 39 | @abstract set marginTop and marginBottom 40 | @param margin 41 | */ 42 | -(void)setMarginHeight:(CGFloat)margin; 43 | 44 | 45 | /////////////////Protected method for internal use///////////////// 46 | /** 47 | @abstract The core layout method. 48 | @protected internal method 49 | @param view layout view 50 | */ 51 | -(void)layout:(UIView *)view; 52 | 53 | /** 54 | @abstract compute the layout size 55 | @protected internal method 56 | @param view layout view 57 | */ 58 | -(CGSize)computeSize:(UIView *)view; 59 | 60 | /** 61 | @abstract compute the layout size 62 | @protected internal method 63 | @param view layout view 64 | @param wHint width 65 | @param hHint height 66 | */ 67 | -(CGSize)computeSize:(UIView *)view wHint:(CGFloat)wHint hHint:(CGFloat)hHint; 68 | 69 | /** 70 | @abstract get the subview,layoutData.exclude == NO 71 | @protected internal method 72 | @param view layout view 73 | */ 74 | -(NSArray *)getUsealbeChildren:(UIView *)view; 75 | 76 | /** 77 | @abstract set marginTop and marginBottom 78 | @protected internal method 79 | @param view subview 80 | @param frame 81 | */ 82 | -(void)setControlFrame:(UIView *)view withFrame:(CGRect)frame; 83 | 84 | @end -------------------------------------------------------------------------------- /CUSLayout/core/CUSLayoutFrame.m: -------------------------------------------------------------------------------- 1 | /** 2 | @version 1.00 2013/4/9 Creation 3 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 4 | */ 5 | 6 | #import "CUSLayoutFrame.h" 7 | #import "CUSLayoutData.h" 8 | #import "CUSLayoutConstant.h" 9 | 10 | 11 | @implementation CUSLayoutFrame 12 | @synthesize marginLeft; 13 | @synthesize marginTop; 14 | @synthesize marginRight; 15 | @synthesize marginBottom; 16 | 17 | -(void)setMargin:(CGFloat)margin{ 18 | [self setMarginWidth:margin]; 19 | [self setMarginHeight:margin]; 20 | } 21 | 22 | -(void)setMarginWidth:(CGFloat)margin{ 23 | self.marginLeft = self.marginRight = margin; 24 | } 25 | 26 | -(void)setMarginHeight:(CGFloat)margin{ 27 | self.marginTop = self.marginBottom = margin; 28 | } 29 | 30 | -(NSArray *)getUsealbeChildren:(UIView *)view{ 31 | NSMutableArray * array = [NSMutableArray array]; 32 | if(!view){ 33 | return array; 34 | } 35 | 36 | for (UIView *subView in view.subviews) { 37 | //ScrollView has two default UIImageView scroller 38 | if ([view isKindOfClass:[UIScrollView class]]) { 39 | if ([subView isKindOfClass:[UIImageView class]]) { 40 | UIImage *image = ((UIImageView *)subView).image; 41 | if ([image isKindOfClass:NSClassFromString(@"_UIResizableImage")]) { 42 | if (image.size.width == 3.5 || image.size.width == 7 || image.size.height == 3.5 || image.size.height == 7) { 43 | continue; 44 | } 45 | } 46 | } 47 | } 48 | 49 | CUSLayoutData *layoutData = subView.layoutData; 50 | if(layoutData && layoutData.exclude){ 51 | continue; 52 | } 53 | [array addObject:subView]; 54 | } 55 | return array; 56 | } 57 | 58 | -(void)layout:(UIView *)view{ 59 | NSLog(@"super layout"); 60 | } 61 | 62 | -(CGSize)computeSize:(UIView *)view{ 63 | CGSize size = [self computeSize:view wHint:CUS_LAY_DEFAULT hHint:CUS_LAY_DEFAULT]; 64 | return size; 65 | } 66 | 67 | -(CGSize)computeSize:(UIView *)view wHint:(CGFloat)wHint hHint:(CGFloat)hHint{ 68 | CGSize size; 69 | if (wHint != CUS_LAY_DEFAULT && hHint != CUS_LAY_DEFAULT) { 70 | size = CGSizeMake(wHint, hHint); 71 | } else { 72 | if (view) { 73 | size = [view sizeThatFits:CGSizeMake(wHint, hHint)]; 74 | }else{ 75 | size = CGSizeMake(32, 32); 76 | } 77 | } 78 | return size; 79 | } 80 | 81 | -(void)setControlFrame:(UIView *)view withFrame:(CGRect)frame{ 82 | view.frame = frame; 83 | } 84 | 85 | @end 86 | -------------------------------------------------------------------------------- /CUSLayout/core/CUSLayoutObject+Util.h: -------------------------------------------------------------------------------- 1 | /** 2 | @header CUSLayoutObject+Util.h 3 | @abstract internal tools 4 | @code 5 | 6 | @link 7 | https://github.com/JJMM/CUSLayout 8 | @version 1.00 2013/4/9 Creation 9 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 10 | */ 11 | 12 | #import 13 | #import 14 | 15 | /** 16 | @class NSMutableArray(CUSLayoutNumber) 17 | @abstract 18 | */ 19 | @interface NSMutableArray(CUSLayoutNumber) 20 | 21 | /** 22 | @abstract internal method 23 | @param value 24 | */ 25 | -(void)addFloat:(CGFloat)value; 26 | 27 | /** 28 | @abstract internal method 29 | @param index 30 | @param value 31 | */ 32 | -(void)replaceFloatAtIndex:(NSInteger)index withFloat:(CGFloat)value; 33 | 34 | /** 35 | @abstract internal method 36 | @param animate 37 | @result CGFloat 38 | */ 39 | -(CGFloat)floatAtIndex:(NSInteger)index; 40 | @end 41 | 42 | 43 | /** 44 | @class NSMutableArray(CUSLayoutCGRect) 45 | @abstract 46 | */ 47 | @interface NSMutableArray(CUSLayoutCGRect) 48 | 49 | /** 50 | @abstract internal method 51 | @param value 52 | */ 53 | -(void)addRect:(CGRect)value; 54 | 55 | /** 56 | @abstract internal method 57 | @param index 58 | @param value 59 | */ 60 | -(void)replaceRectAtIndex:(NSInteger)index withRect:(CGRect)value; 61 | 62 | /** 63 | @abstract internal method 64 | @param index 65 | @result CGRect 66 | */ 67 | -(CGRect)CGRectAtIndex:(NSInteger)index; 68 | @end 69 | 70 | 71 | /** 72 | @class CUS2DArray 73 | @abstract 74 | */ 75 | @interface CUS2DArray : NSObject 76 | @property (nonatomic,assign) NSInteger rowCount; 77 | @property (nonatomic,assign,readonly) NSInteger columnCount; 78 | 79 | -(id)init:(NSInteger)rowCount atColumnCount:(NSInteger)columnCount; 80 | - (id)objectAtRow:(NSInteger)row atColumn:(NSInteger)column; 81 | - (void)addObject:(id)anObject atRow:(NSInteger)row atColumn:(NSInteger)column; 82 | - (void)removeObjectAtRow:(NSInteger)row atColumn:(NSInteger)column; 83 | @end -------------------------------------------------------------------------------- /CUSLayout/core/CUSLayoutObject+Util.m: -------------------------------------------------------------------------------- 1 | /** 2 | @version 1.00 2013/4/9 Creation 3 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 4 | */ 5 | 6 | #import "CUSLayoutObject+Util.h" 7 | 8 | 9 | @implementation NSMutableArray(CUSLayoutNumber) 10 | -(void)addFloat:(CGFloat)value{ 11 | NSNumber *number = [NSNumber numberWithFloat:value]; 12 | [self addObject:number]; 13 | } 14 | 15 | -(void)replaceFloatAtIndex:(NSInteger)index withFloat:(CGFloat)value{ 16 | NSNumber *number = [NSNumber numberWithFloat:value]; 17 | [self replaceObjectAtIndex:index withObject:number]; 18 | } 19 | -(CGFloat)floatAtIndex:(NSInteger)index{ 20 | NSNumber *number = [self objectAtIndex:index]; 21 | return [number floatValue]; 22 | } 23 | 24 | @end 25 | 26 | @implementation NSMutableArray(CUSLayoutCGRect) 27 | -(void)addRect:(CGRect)value{ 28 | NSValue *nsValue = [NSValue valueWithCGRect:value]; 29 | [self addObject:nsValue]; 30 | } 31 | 32 | -(void)replaceRectAtIndex:(NSInteger)index withRect:(CGRect)value{ 33 | NSValue *nsValue = [NSValue valueWithCGRect:value]; 34 | [self replaceObjectAtIndex:index withObject:nsValue]; 35 | } 36 | -(CGRect)CGRectAtIndex:(NSInteger)index{ 37 | NSValue *nsValue = [self objectAtIndex:index]; 38 | return [nsValue CGRectValue]; 39 | } 40 | 41 | @end 42 | 43 | 44 | 45 | 46 | @implementation CUS2DArray{ 47 | NSMutableArray *mainArray; 48 | 49 | } 50 | @synthesize rowCount = _rowCount; 51 | @synthesize columnCount = _columnCount; 52 | 53 | -(id)init:(NSInteger)rowCount atColumnCount:(NSInteger)columnCount{ 54 | self = [super init]; 55 | if (self) { 56 | _rowCount = rowCount; 57 | _columnCount = columnCount; 58 | mainArray = [self buildArray:rowCount atColumn:columnCount]; 59 | } 60 | return self; 61 | } 62 | 63 | -(void)setRowCount:(NSInteger)rowCount{ 64 | if (rowCount<=_rowCount) { 65 | return; 66 | } 67 | 68 | for (NSInteger i = _rowCount; i < rowCount; i++) { 69 | NSMutableArray *rowArray = [NSMutableArray array]; 70 | for (int j = 0; j < self.columnCount; j++) { 71 | [rowArray addObject:[NSNull null]]; 72 | } 73 | [mainArray addObject:rowArray]; 74 | } 75 | _rowCount = rowCount; 76 | } 77 | -(NSMutableArray *)buildArray:(NSInteger)rowCount atColumn:(NSInteger)columnCount{ 78 | NSMutableArray *array = [NSMutableArray array]; 79 | 80 | for (int i = 0; i < rowCount; i++) { 81 | NSMutableArray *rowArray = [NSMutableArray array]; 82 | for (int j = 0; j < columnCount; j++) { 83 | [rowArray addObject:[NSNull null]]; 84 | } 85 | [array addObject:rowArray]; 86 | } 87 | return array; 88 | } 89 | 90 | - (id)objectAtRow:(NSInteger)row atColumn:(NSInteger)column{ 91 | if (row < self.rowCount) { 92 | NSMutableArray * rowArray = [mainArray objectAtIndex:row]; 93 | if (column < self.columnCount) { 94 | id obj = [rowArray objectAtIndex:column]; 95 | if ([NSNull null] == obj) { 96 | return nil; 97 | }else{ 98 | return obj; 99 | } 100 | } 101 | } 102 | return nil; 103 | } 104 | - (void)addObject:(id)anObject atRow:(NSInteger)row atColumn:(NSInteger)column{ 105 | if (row < self.rowCount) { 106 | NSMutableArray * rowArray = [mainArray objectAtIndex:row]; 107 | if (column < self.columnCount) { 108 | [rowArray replaceObjectAtIndex:column withObject:anObject]; 109 | return; 110 | } 111 | } 112 | NSLog(@"2D array insert error:%@ row:%i column:%i", anObject, (int)row, (int)column); 113 | } 114 | - (void)removeObjectAtRow:(NSInteger)row atColumn:(NSInteger)column{ 115 | if (row < self.rowCount) { 116 | NSMutableArray * rowArray = [mainArray objectAtIndex:row]; 117 | if (column < self.columnCount) { 118 | [rowArray replaceObjectAtIndex:column withObject:[NSNull null]]; 119 | return; 120 | } 121 | } 122 | NSLog(@"2D array delete error:row:%i column:%i", (int)row, (int)column); 123 | } 124 | 125 | -(NSString *)description{ 126 | NSMutableString *str = [NSMutableString stringWithString:@"\n==========CUS2DArray===========\n"]; 127 | for (int i = 0; i < self.rowCount; i++) { 128 | NSMutableArray *rowArray = [mainArray objectAtIndex:i]; 129 | for (int j = 0; j < self.columnCount; j++) { 130 | id obj = [rowArray objectAtIndex:j]; 131 | [str appendString:[[obj class] description]]; 132 | [str appendString:@" "]; 133 | } 134 | [str appendString:@"\n"]; 135 | } 136 | return str; 137 | }; 138 | @end -------------------------------------------------------------------------------- /CUSLayout/core/UIView+CUSLayout.h: -------------------------------------------------------------------------------- 1 | /** 2 | @header UIVIew+CUSLayout.h 3 | @abstract 4 | @code 5 | 6 | @link 7 | https://github.com/JJMM/CUSLayout 8 | @version 1.00 2013/4/9 Creation 9 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 10 | */ 11 | 12 | #import 13 | #import 14 | @class CUSLayoutFrame; 15 | @class CUSLayoutData; 16 | 17 | /** 18 | @class CUSGridData(Factory) 19 | @abstract 20 | add layoutFrame,layoutData. 21 | */ 22 | @interface UIView(UIView_CUSLayout){ 23 | 24 | } 25 | @property (nonatomic,strong,getter = getLayoutFrame) CUSLayoutFrame *layoutFrame; 26 | @property (nonatomic,strong,getter = getLayoutData) CUSLayoutData *layoutData; 27 | 28 | /** 29 | @abstract get useable layout size from view.It is used to remove the border. 30 | @param margin 31 | */ 32 | -(CGRect)getClientArea; 33 | 34 | /** 35 | @abstract compte the best size by the UIView and subViews.Sometimes,it's equal to sizeThatFits.Container view compute by layoutframe. 36 | @param margin 37 | */ 38 | -(CGSize)computeSize:(CGSize)size; 39 | 40 | /** 41 | @abstract Do not need to call the method.except: 42 | 1.view has rendered,then change the value of layoutFrame or layoutData 43 | 2.add or remove view from parentView 44 | */ 45 | -(void)CUSLayout; 46 | 47 | /** 48 | @abstract Do not need to call the method. 49 | @param animate 50 | */ 51 | -(void)CUSLayout:(BOOL)animate; 52 | 53 | /** 54 | @abstract Do not need to call the method. 55 | @param animate 56 | @param duration default value is 0.5s 57 | */ 58 | -(void)CUSLayout:(BOOL)animate withDuration:(NSTimeInterval)duration; 59 | @end 60 | 61 | 62 | /** 63 | @class UIScrollView(UIScrollView_CUSLayout) 64 | @abstract compute clientArea size by contentSize 65 | */ 66 | @interface UIScrollView(UIScrollView_CUSLayout){ 67 | } 68 | @end -------------------------------------------------------------------------------- /CUSLayout/core/UIView+CUSLayout.m: -------------------------------------------------------------------------------- 1 | /** 2 | @version 1.00 2013/4/9 Creation 3 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 4 | */ 5 | 6 | #import "UIView+CUSLayout.h" 7 | #import 8 | #import "CUSLayoutConstant.h" 9 | #import "CUSLayoutFrame.h" 10 | #import "CUSLayoutData.h" 11 | static NSString *UIView_CUSLayoutFrame; 12 | static NSString *UIView_CUSLayoutData; 13 | 14 | @implementation UIView(UIView_CUSLayout) 15 | @dynamic layoutFrame; 16 | @dynamic layoutData; 17 | 18 | //#pragma CUSLayout working mechanism 19 | //CUSLayout 工作机制:通过当前View大小变化触发layoutSubviews方法,layoutSubviews中调用布局算法 20 | //重新设置所有子控件Frame,当子控件大小发生变化时,循环触发此机制,达到递归调用布局算法的目的. 21 | 22 | -(void)layoutSubviewsExt{ 23 | CUSLayoutFrame *layoutFrame = [self getLayoutFrame]; 24 | if(layoutFrame){ 25 | [layoutFrame layout:self]; 26 | } 27 | //此方法已和layoutSubviews方法互换,并非调用自身,实际上是调用[super layoutSubviews],所以不会引起死循环 28 | [self layoutSubviewsExt]; 29 | } 30 | 31 | #pragma implement API 32 | -(CGRect)getClientArea{ 33 | return self.bounds; 34 | } 35 | -(CGSize)computeSize:(CGSize)size{ 36 | if (size.width != CUS_LAY_DEFAULT && size.height != CUS_LAY_DEFAULT) { 37 | return size; 38 | } 39 | CGSize s = CGSizeMake(size.width, size.height); 40 | if(self.layoutFrame == nil){ 41 | s = [self sizeThatFits:size]; 42 | }else{ 43 | s = [self.layoutFrame computeSize:self wHint:size.width hHint:size.height]; 44 | } 45 | 46 | if (s.width <= 0 || s.height <= 0) { 47 | CGFloat maxWidth = s.width; 48 | CGFloat maxHeight = s.height; 49 | for (UIView *subView in self.subviews) { 50 | maxWidth = MAX(maxWidth, subView.frame.origin.x + subView.frame.size.width); 51 | maxHeight = MAX(maxHeight, subView.frame.origin.y + subView.frame.size.height); 52 | } 53 | s = CGSizeMake(maxWidth, maxHeight); 54 | } 55 | 56 | if(size.width != CUS_LAY_DEFAULT){ 57 | s.width = size.width; 58 | } 59 | if(size.height != CUS_LAY_DEFAULT){ 60 | s.height = size.height; 61 | } 62 | return s; 63 | } 64 | -(void)setLayoutFrame:(CUSLayoutFrame *)layoutFrame{ 65 | objc_setAssociatedObject(self, &UIView_CUSLayoutFrame, 66 | layoutFrame, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 67 | } 68 | 69 | 70 | -(CUSLayoutFrame *)getLayoutFrame{ 71 | CUSLayoutFrame * layoutFrame = objc_getAssociatedObject(self, &UIView_CUSLayoutFrame); 72 | return layoutFrame; 73 | } 74 | 75 | -(void)setLayoutData:(CUSLayoutData *)layoutData{ 76 | objc_setAssociatedObject(self, &UIView_CUSLayoutData, 77 | layoutData, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 78 | } 79 | 80 | -(CUSLayoutData *)getLayoutData{ 81 | CUSLayoutData * layoutData = objc_getAssociatedObject(self, &UIView_CUSLayoutData); 82 | return layoutData; 83 | } 84 | 85 | -(void)CUSLayout{ 86 | [self layoutSubviews]; 87 | } 88 | 89 | -(void)CUSLayout:(BOOL)animate{ 90 | [self CUSLayout:animate withDuration:0.5]; 91 | } 92 | 93 | -(void)CUSLayout:(BOOL)animate withDuration:(NSTimeInterval)duration{ 94 | [self CUSLayout:animate withDuration:duration completion:nil]; 95 | } 96 | 97 | -(void)CUSLayout:(BOOL)animate withDuration:(NSTimeInterval)duration completion:(void (^)(BOOL finished))completion { 98 | if(animate){ 99 | [UIView animateWithDuration:duration animations:^{ 100 | [self CUSLayout]; 101 | } completion:completion]; 102 | }else{ 103 | [self CUSLayout]; 104 | if (completion) { 105 | completion(YES); 106 | } 107 | } 108 | } 109 | //IOS6中autoresizesSubviews的View必须调用UIView中的layoutSubviews,而Catogory覆盖的方法不能调用super中的方法 110 | //因此将布局递归机制通过交换方法实现 111 | + (void) load 112 | { 113 | static dispatch_once_t onceToken; 114 | dispatch_once(&onceToken, ^{ 115 | method_exchangeImplementations(class_getInstanceMethod([UIView class], @selector(layoutSubviewsExt)), class_getInstanceMethod([self class], @selector(layoutSubviews))); 116 | }); 117 | } 118 | @end 119 | 120 | 121 | @implementation UIScrollView(UIScrollView_CUSLayout) 122 | -(CGRect)getClientArea{ 123 | if(self.contentSize.width == 0 && self.contentSize.height == 0){ 124 | return self.bounds; 125 | }else{ 126 | return CGRectMake(0, 0, self.contentSize.width, self.contentSize.height); 127 | } 128 | } 129 | @end 130 | -------------------------------------------------------------------------------- /CUSLayout/extend/CUSLayoutDesignerView.h: -------------------------------------------------------------------------------- 1 | /** 2 | @header CUSLayoutDesignerView.h 3 | @abstract 4 | @code 5 | 6 | @link 7 | https://github.com/JJMM/CUSLayout 8 | @version 1.00 2013/4/9 Creation 9 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 10 | */ 11 | 12 | #import 13 | 14 | /** 15 | @class CUSLayoutDesignerView 16 | @abstract 17 | */ 18 | @interface CUSLayoutDesignerView : UIView 19 | @property (nonatomic,assign) BOOL dragAndDropEnable; 20 | @property (nonatomic,assign) CGFloat dragScale; 21 | 22 | 23 | //you can override the 3 method to designe youself drag animation. 24 | -(void)dragBegan:(CGPoint)touchPoint; 25 | -(void)dragChanged:(CGPoint)touchPoint; 26 | -(void)dragEnd; 27 | @end -------------------------------------------------------------------------------- /CUSLayout/extend/CUSLayoutDesignerView.m: -------------------------------------------------------------------------------- 1 | /** 2 | @version 1.00 2013/4/9 Creation 3 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 4 | */ 5 | 6 | #import "CUSLayoutDesignerView.h" 7 | #import "UIView+CUSLayout.h" 8 | #import "CUSLayoutData.h" 9 | 10 | @implementation CUSLayoutDesignerView{ 11 | UIView *pickedView; 12 | CGRect pickedViewFrame; 13 | CGPoint beganPoint; 14 | BOOL picked; 15 | UIView *placedView; 16 | } 17 | @synthesize dragAndDropEnable; 18 | @synthesize dragScale; 19 | - (id)init 20 | { 21 | self = [super init]; 22 | if (self) { 23 | [self initView]; 24 | } 25 | return self; 26 | } 27 | 28 | 29 | -(void)initView{ 30 | self.dragAndDropEnable = YES; 31 | self.dragScale = 1.1; 32 | UILongPressGestureRecognizer *gestureRecognizer = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressGestureRecognizerHandle:)]; 33 | [self addGestureRecognizer:gestureRecognizer]; 34 | } 35 | 36 | -(void)dragBegan:(CGPoint)touchPoint{ 37 | placedView = [[UIView alloc]init]; 38 | placedView.alpha = 0; 39 | placedView.frame = pickedView.frame; 40 | [self addSubview:placedView]; 41 | 42 | [self exchangeSubviewAtObject:placedView withSubview:pickedView]; 43 | 44 | placedView.layoutData = pickedView.layoutData; 45 | 46 | CUSLayoutData *layoutData = [[CUSLayoutData alloc]init]; 47 | layoutData.exclude = YES; 48 | pickedView.layoutData = layoutData; 49 | 50 | CGRect pickedFrame = [self getScaleRect:pickedView.frame withScale:self.dragScale]; 51 | [UIView animateWithDuration:0.5 animations:^{ 52 | pickedView.frame = pickedFrame; 53 | }]; 54 | pickedViewFrame = pickedFrame; 55 | } 56 | 57 | -(void)dragChanged:(CGPoint)touchPoint{ 58 | UIView *upperView = [self getUpperViewByPoint:touchPoint exceptView:pickedView]; 59 | if(upperView!=nil && upperView != pickedView && upperView != placedView){ 60 | 61 | [self exchangeSubviewAtObject:placedView withSubview:upperView]; 62 | 63 | [self CUSLayout:YES]; 64 | CGRect pickedFrame = [self getScaleRect:placedView.frame withScale:self.dragScale]; 65 | [UIView animateWithDuration:0.5 animations:^{ 66 | pickedView.frame = CGRectMake(pickedView.frame.origin.x, pickedView.frame.origin.y, pickedFrame.size.width, pickedFrame.size.height); 67 | pickedViewFrame.size.width = pickedFrame.size.width; 68 | pickedViewFrame.size.height = pickedFrame.size.height; 69 | }]; 70 | }else{ 71 | CGFloat x = pickedViewFrame.origin.x + (touchPoint.x - beganPoint.x); 72 | CGFloat y = pickedViewFrame.origin.y + (touchPoint.y - beganPoint.y); 73 | CGFloat width = pickedView.frame.size.width; 74 | CGFloat height = pickedView.frame.size.height; 75 | CGRect viewFrame = CGRectMake(x, y, width, height); 76 | [UIView animateWithDuration:0.5 animations:^{ 77 | pickedView.frame = viewFrame; 78 | }]; 79 | } 80 | } 81 | 82 | -(void)dragEnd{ 83 | if(placedView){ 84 | [self exchangeSubviewAtObject:placedView withSubview:pickedView]; 85 | pickedView.layoutData = placedView.layoutData; 86 | 87 | [placedView removeFromSuperview]; 88 | placedView = nil; 89 | } 90 | pickedView = nil; 91 | 92 | [self CUSLayout:YES]; 93 | } 94 | -(void)longPressGestureRecognizerHandle:(UILongPressGestureRecognizer *)gestureRecognizer{ 95 | CGPoint touchPoint = [gestureRecognizer locationInView:self]; 96 | if (gestureRecognizer.state == UIGestureRecognizerStateBegan) { 97 | if (!dragAndDropEnable) { 98 | return; 99 | } 100 | if(picked){ 101 | return; 102 | } 103 | CGPoint touchPoint = [gestureRecognizer locationInView:self]; 104 | UIView *pView = [self getViewByPoint:touchPoint]; 105 | if (pView == nil) { 106 | return; 107 | } 108 | picked = YES; 109 | beganPoint = touchPoint; 110 | pickedView = pView; 111 | pickedViewFrame = pView.frame; 112 | 113 | [self dragBegan:touchPoint]; 114 | } 115 | else if (gestureRecognizer.state == UIGestureRecognizerStateChanged) { 116 | if (picked) { 117 | [self dragChanged:touchPoint]; 118 | 119 | } 120 | } 121 | else { 122 | if(!picked){ 123 | return; 124 | } 125 | picked = NO; 126 | 127 | [self dragEnd]; 128 | } 129 | } 130 | 131 | - (void)exchangeSubviewAtObject:(UIView *)view1 withSubview:(UIView *)view2{ 132 | NSInteger index1 = [self.subviews indexOfObject:view1]; 133 | NSInteger index2 = [self.subviews indexOfObject:view2]; 134 | 135 | [self exchangeSubviewAtIndex:index1 withSubviewAtIndex:index2]; 136 | } 137 | 138 | -(CGRect)getScaleRect:(CGRect)frame withScale:(CGFloat)scale{ 139 | CGFloat width = frame.size.width * scale; 140 | CGFloat height = frame.size.height * scale; 141 | CGFloat x = frame.origin.x + (frame.size.width - width)/2.0; 142 | CGFloat y = frame.origin.y + (frame.size.height - height)/2.0; 143 | return CGRectMake(x, y, width, height); 144 | } 145 | -(UIView *)getViewByPoint:(CGPoint)point{ 146 | for (UIView *subView in self.subviews) { 147 | if ([self RectContainsPoint:subView.frame withCGPoint:point]) { 148 | return subView; 149 | } 150 | } 151 | return nil; 152 | } 153 | 154 | -(UIView *)getUpperViewByPoint:(CGPoint)point exceptView:(UIView *)exView{ 155 | for (UIView *subView in self.subviews) { 156 | if (subView == exView) { 157 | continue; 158 | } 159 | CGRect upperFrame = subView.frame; 160 | upperFrame.origin.x += upperFrame.size.width/6.0; 161 | upperFrame.origin.y += upperFrame.size.height/6.0; 162 | 163 | upperFrame.size.width -= upperFrame.size.width/3.0; 164 | upperFrame.size.height -= upperFrame.size.height/3.0; 165 | 166 | if ([self RectContainsPoint:upperFrame withCGPoint:point]) { 167 | return subView; 168 | } 169 | } 170 | return nil; 171 | } 172 | 173 | 174 | //Don't need to import CoreGraphics Lib 175 | //simple to bool CGRectContainsPoint(CGRect rect, CGPoint point) 176 | -(BOOL)RectContainsPoint:(CGRect) rect withCGPoint:(CGPoint) point{ 177 | if(point.x < rect.origin.x){ 178 | return NO; 179 | } 180 | 181 | if(point.x > rect.origin.x + rect.size.width){ 182 | return NO; 183 | } 184 | 185 | if(point.y < rect.origin.y){ 186 | return NO; 187 | } 188 | 189 | if(point.y > rect.origin.y + rect.size.height){ 190 | return NO; 191 | } 192 | 193 | return YES; 194 | } 195 | @end 196 | -------------------------------------------------------------------------------- /CUSLayout/util/CUSLayoutUtil.h: -------------------------------------------------------------------------------- 1 | /** 2 | @header CUSLayoutUtil.h 3 | @abstract 4 | @code 5 | 6 | @link 7 | https://github.com/JJMM/CUSLayout 8 | @version 1.00 2013/4/9 Creation 9 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 10 | */ 11 | 12 | #import 13 | #import 14 | 15 | #import "CUSLayoutFrame.h" 16 | #import "CUSLayoutData.h" 17 | 18 | #import "CUSFillLayout.h" 19 | #import "CUSLinearLayout.h" 20 | #import "CUSLinearData.h" 21 | #import "CUSRowLayout.h" 22 | #import "CUSRowData.h" 23 | #import "CUSTableLayout.h" 24 | #import "CUSTableData.h" 25 | 26 | /** 27 | @class CUSLayoutUtil 28 | @abstract 29 | 静态工具类 30 | 注意,此类中提供的对象是全局共用对象,不能修改任何成员变量,否则会影响到共用此对象的布局 31 | */ 32 | 33 | @interface CUSLayoutUtil : NSObject 34 | @property (nonatomic,strong) CUSFillLayout *share_fillLayout_H; 35 | @property (nonatomic,strong) CUSFillLayout *share_fillLayout_V; 36 | 37 | @property (nonatomic,strong) CUSLinearLayout *share_linearLayout_H; 38 | @property (nonatomic,strong) CUSLinearLayout *share_linearLayout_V; 39 | @property (nonatomic,strong) CUSLinearData *share_linearData; 40 | 41 | @property (nonatomic,strong) CUSRowLayout *share_rowLayout_H; 42 | @property (nonatomic,strong) CUSRowLayout *share_rowLayout_V; 43 | @property (nonatomic,strong) CUSRowData *share_rowData; 44 | 45 | @property (nonatomic,strong) CUSTableData *share_tableData; 46 | 47 | +(CUSLayoutUtil *)getShareInstance; 48 | @end 49 | 50 | -------------------------------------------------------------------------------- /CUSLayout/util/CUSLayoutUtil.m: -------------------------------------------------------------------------------- 1 | /** 2 | @version 1.00 2013/4/9 Creation 3 | @copyright Copyright (c) 2013 zhangyu. All rights reserved. 4 | */ 5 | 6 | #import "CUSLayoutUtil.h" 7 | 8 | static CUSLayoutUtil *CUSLayoutInstance; 9 | @implementation CUSLayoutUtil 10 | @synthesize share_fillLayout_H; 11 | @synthesize share_fillLayout_V; 12 | 13 | @synthesize share_linearLayout_H; 14 | @synthesize share_linearLayout_V; 15 | @synthesize share_linearData; 16 | 17 | @synthesize share_rowLayout_H; 18 | @synthesize share_rowLayout_V; 19 | @synthesize share_rowData; 20 | 21 | @synthesize share_tableData; 22 | - (id)init 23 | { 24 | self = [super init]; 25 | if (self) { 26 | self.share_fillLayout_H = [[CUSFillLayout alloc]init]; 27 | self.share_fillLayout_V = [[CUSFillLayout alloc]init]; 28 | self.share_fillLayout_V.type = CUSLayoutTypeVertical; 29 | 30 | self.share_rowLayout_H = [[CUSRowLayout alloc]init]; 31 | self.share_rowLayout_V = [[CUSRowLayout alloc]init]; 32 | self.share_rowLayout_V.type = CUSLayoutTypeVertical; 33 | 34 | self.share_rowData = [[CUSRowData alloc]init]; 35 | 36 | self.share_linearLayout_H = [[CUSLinearLayout alloc]init]; 37 | self.share_linearLayout_H.type = CUSLayoutTypeHorizontal; 38 | self.share_linearLayout_V = [[CUSLinearLayout alloc]init]; 39 | 40 | self.share_linearData = [[CUSLinearData alloc]init]; 41 | self.share_tableData = [[CUSTableData alloc]init]; 42 | 43 | } 44 | return self; 45 | } 46 | 47 | +(CUSLayoutUtil *)getShareInstance{ 48 | if (!CUSLayoutInstance) { 49 | CUSLayoutInstance = [[CUSLayoutUtil alloc]init]; 50 | } 51 | return CUSLayoutInstance; 52 | } 53 | @end 54 | -------------------------------------------------------------------------------- /CUSLayoutExample/CUSAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // CUSAppDelegate.h 3 | // CUSLayoutExample 4 | // 5 | // Created by zhangyu on 14-5-21. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CUSAppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /CUSLayoutExample/CUSAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSAppDelegate.m 3 | // CUSLayoutExample 4 | // 5 | // Created by zhangyu on 14-5-21. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSAppDelegate.h" 10 | #import "CUSMainViewController.h" 11 | @implementation CUSAppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14 | { 15 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 16 | // Override point for customization after application launch. 17 | self.window.backgroundColor = [UIColor whiteColor]; 18 | CUSMainViewController *mainController = [[CUSMainViewController alloc]init]; 19 | UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:mainController]; 20 | self.window.rootViewController = nav; 21 | 22 | [self.window makeKeyAndVisible]; 23 | return YES; 24 | } 25 | 26 | - (void)applicationWillResignActive:(UIApplication *)application 27 | { 28 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 29 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 30 | } 31 | 32 | - (void)applicationDidEnterBackground:(UIApplication *)application 33 | { 34 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 35 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 36 | } 37 | 38 | - (void)applicationWillEnterForeground:(UIApplication *)application 39 | { 40 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 41 | } 42 | 43 | - (void)applicationDidBecomeActive:(UIApplication *)application 44 | { 45 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 46 | } 47 | 48 | - (void)applicationWillTerminate:(UIApplication *)application 49 | { 50 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 51 | } 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /CUSLayoutExample/CUSLayoutExample-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | CUSLayout 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.zhangyu.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.1.6 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.1.6 25 | LSRequiresIPhoneOS 26 | 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /CUSLayoutExample/CUSLayoutExample-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_3_0 10 | #warning "This project uses features only available in iOS SDK 3.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #import 16 | 17 | #endif -------------------------------------------------------------------------------- /CUSLayoutExample/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "40x40", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "60x60", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "ipad", 20 | "size" : "29x29", 21 | "scale" : "1x" 22 | }, 23 | { 24 | "idiom" : "ipad", 25 | "size" : "29x29", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "ipad", 30 | "size" : "40x40", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "40x40", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "76x76", 41 | "scale" : "1x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "76x76", 46 | "scale" : "2x" 47 | } 48 | ], 49 | "info" : { 50 | "version" : 1, 51 | "author" : "xcode" 52 | } 53 | } -------------------------------------------------------------------------------- /CUSLayoutExample/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "orientation" : "portrait", 20 | "idiom" : "ipad", 21 | "extent" : "full-screen", 22 | "minimum-system-version" : "7.0", 23 | "scale" : "1x" 24 | }, 25 | { 26 | "orientation" : "landscape", 27 | "idiom" : "ipad", 28 | "extent" : "full-screen", 29 | "minimum-system-version" : "7.0", 30 | "scale" : "1x" 31 | }, 32 | { 33 | "orientation" : "portrait", 34 | "idiom" : "ipad", 35 | "extent" : "full-screen", 36 | "minimum-system-version" : "7.0", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "orientation" : "landscape", 41 | "idiom" : "ipad", 42 | "extent" : "full-screen", 43 | "minimum-system-version" : "7.0", 44 | "scale" : "2x" 45 | } 46 | ], 47 | "info" : { 48 | "version" : 1, 49 | "author" : "xcode" 50 | } 51 | } -------------------------------------------------------------------------------- /CUSLayoutExample/Resources/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JJMM/CUSLayout/392c10a7d0a1fa0d27d64fa1b91d34c5dad9dd0e/CUSLayoutExample/Resources/Icon.png -------------------------------------------------------------------------------- /CUSLayoutExample/Resources/Icon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JJMM/CUSLayout/392c10a7d0a1fa0d27d64fa1b91d34c5dad9dd0e/CUSLayoutExample/Resources/Icon@2x.png -------------------------------------------------------------------------------- /CUSLayoutExample/Resources/README.txt: -------------------------------------------------------------------------------- 1 | Open source release of automatic layout framework for iOS,which is simlar to Android,SWT,SWING API.It solves the problem of iPhone, iPhone5, iPad, resolution, rotation etc. 2 | 1.Simplify coding, you do not need to take into account the pixel level, only for regional programming, which greatly improves the efficiency of programming 3 | 2.Good readability, layout type can be a preliminary understanding of layout intent and child controls roughly placed, eliminating the need for a very tedious restore coordinate steps 4 | 3.When the the UIView container Flip, size change, supporting multiple resolutions, automatic processing 5 | 4.UIView category which makes it easy to create layout constraints in old code 6 | 5.The API is simple and easy-to-use, low cost learning through the sample program to preliminary master 7 | 8 | https://github.com/JJMM/CUSLayout -------------------------------------------------------------------------------- /CUSLayoutExample/controller/advanced/CUSGridLayoutSampleViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CUSGridLayoutSampleViewController.h 3 | // CUSLayout 4 | // 5 | // Created by zhangyu on 13-7-19. 6 | // 7 | // 8 | 9 | #import 10 | #import "CUSLayoutSampleFactory.h" 11 | @interface CUSGridLayoutSampleViewController : CUSViewController 12 | @property (nonatomic,strong) IBOutlet UIView *contentView; 13 | @property (nonatomic,strong) IBOutlet UIScrollView *scrollView; 14 | -(IBAction)toolItemClicked:(id)sender; 15 | @end 16 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/advanced/CUSGridLayoutSampleViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSGridLayoutSampleViewController.m 3 | // CUSLayout 4 | // 5 | // Created by zhangyu on 13-7-19. 6 | // 7 | // 8 | 9 | #import "CUSGridLayoutSampleViewController.h" 10 | 11 | @implementation CUSGridLayoutSampleViewController 12 | @synthesize contentView; 13 | @synthesize scrollView; 14 | 15 | //rotation 16 | -(void)viewDidLayoutSubviews{ 17 | [super viewDidLayoutSubviews]; 18 | 19 | self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 2, 44); 20 | [self.scrollView CUSLayout]; 21 | } 22 | //for ipad of ios4 23 | -(void)viewWillAppear:(BOOL)animated{ 24 | [super viewWillAppear:animated]; 25 | self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 2, 44); 26 | [self.scrollView CUSLayout]; 27 | } 28 | - (void)viewDidLoad{ 29 | [super viewDidLoad]; 30 | 31 | NSInteger controlCounter = 6; 32 | for (int i = 0; i < controlCounter; i++) { 33 | UIView *button = [CUSLayoutSampleFactory createControl:[NSString stringWithFormat:@"button%i",i]]; 34 | button.layoutData = [CUSGridData createGrab]; 35 | [self.contentView addSubview:button]; 36 | } 37 | 38 | CUSGridLayout *layout = [[CUSGridLayout alloc]initWithNumColumns:2]; 39 | self.contentView.layoutFrame = layout; 40 | 41 | self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 2, 44); 42 | CUSFillLayout *fillLayout = [[CUSFillLayout alloc]init]; 43 | fillLayout.spacing = 0; 44 | self.scrollView.layoutFrame = fillLayout; 45 | 46 | UIBarButtonItem *toolButton = [[UIBarButtonItem alloc]initWithTitle:@"tool" style:UIBarButtonItemStyleBordered target:self action:@selector(toolButtonClicked)]; 47 | self.navigationItem.rightBarButtonItem = toolButton; 48 | } 49 | 50 | -(IBAction)toolItemClicked:(id)sender{ 51 | UIBarButtonItem *btn = (UIBarButtonItem *)sender; 52 | CUSGridLayout *layout = (CUSGridLayout *)self.contentView.layoutFrame; 53 | if(btn.tag == 1){ 54 | layout.verticalSpacing -= 5; 55 | layout.horizontalSpacing -=5; 56 | if(layout.verticalSpacing < 0){ 57 | layout.verticalSpacing = 0; 58 | } 59 | if(layout.horizontalSpacing < 0){ 60 | layout.horizontalSpacing = 0; 61 | } 62 | }else if(btn.tag == 2){ 63 | layout.verticalSpacing += 5; 64 | layout.horizontalSpacing +=5; 65 | }else if(btn.tag == 3){ 66 | NSArray *array = self.contentView.subviews; 67 | if(array && [array count] > 0){ 68 | UIView *lastView = [array lastObject]; 69 | [lastView removeFromSuperview]; 70 | } 71 | }else if(btn.tag == 4){ 72 | UIView *button = [CUSLayoutSampleFactory createControl:[NSString stringWithFormat:@"button%i",(int)[self.contentView.subviews count]]]; 73 | button.layoutData = [CUSGridData createGrab]; 74 | [self.contentView addSubview:button]; 75 | }else if(btn.tag == 5){ 76 | layout.numColumns -=1; 77 | if(layout.numColumns < 1){ 78 | layout.numColumns = 1; 79 | } 80 | }else if(btn.tag == 6){ 81 | layout.numColumns +=1; 82 | if(layout.numColumns < 1){ 83 | layout.numColumns = 1; 84 | } 85 | } 86 | 87 | [self.contentView CUSLayout:YES]; 88 | } 89 | 90 | -(void)toolButtonClicked{ 91 | if (self.scrollView.contentOffset.x == 0) { 92 | [self.scrollView setContentOffset:CGPointMake(self.scrollView.frame.size.width, 0) animated:YES]; 93 | }else{ 94 | [self.scrollView setContentOffset:CGPointMake(0, 0) animated:YES]; 95 | } 96 | } 97 | @end -------------------------------------------------------------------------------- /CUSLayoutExample/controller/advanced/CUSRowLayoutSampleViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CUSRowLayoutSampleViewController.h 3 | // CUSLayout 4 | // 5 | // Created by zhangyu on 13-4-10. 6 | // Copyright (c) 2013年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CUSLayoutSampleFactory.h" 11 | @interface CUSRowLayoutSampleViewController : CUSViewController 12 | @property (nonatomic,strong) IBOutlet UIView *contentView; 13 | @property (nonatomic,strong) IBOutlet UIScrollView *scrollView; 14 | 15 | -(IBAction)toolItemClicked:(id)sender; 16 | @end 17 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/advanced/CUSRowLayoutSampleViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSRowLayoutSampleViewController.m 3 | // CUSLayout 4 | // 5 | // Created by zhangyu on 13-4-10. 6 | // Copyright (c) 2013年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSRowLayoutSampleViewController.h" 10 | 11 | @implementation CUSRowLayoutSampleViewController 12 | @synthesize contentView; 13 | @synthesize scrollView; 14 | 15 | //rotation 16 | -(void)viewDidLayoutSubviews{ 17 | [super viewDidLayoutSubviews]; 18 | self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 2, 44); 19 | [self.scrollView CUSLayout]; 20 | } 21 | 22 | //for ipad of ios4 23 | -(void)viewWillAppear:(BOOL)animated{ 24 | [super viewWillAppear:animated]; 25 | self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 2, 44); 26 | [self.scrollView CUSLayout]; 27 | } 28 | 29 | -(void)buttonClicked:(id)sender{ 30 | NSLog(@"buttonClicked:%@",sender); 31 | } 32 | - (void)viewDidLoad{ 33 | [super viewDidLoad]; 34 | for (int i = 0; i < 15; i++) { 35 | UIButton *button = (UIButton *)[CUSLayoutSampleFactory createControl]; 36 | button.layoutData = CUSLAYOUT.share_rowData; 37 | [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; 38 | [self.contentView addSubview:button]; 39 | } 40 | 41 | CUSRowLayout *layout = [[CUSRowLayout alloc]init]; 42 | self.contentView.layoutFrame = layout; 43 | 44 | self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 2, 44); 45 | 46 | CUSFillLayout *fillLayout = [[CUSFillLayout alloc]init]; 47 | fillLayout.spacing = 0; 48 | self.scrollView.layoutFrame = fillLayout; 49 | 50 | UIBarButtonItem *toolButton = [[UIBarButtonItem alloc]initWithTitle:@"tool" style:UIBarButtonItemStyleBordered target:self action:@selector(toolButtonClicked)]; 51 | self.navigationItem.rightBarButtonItem = toolButton; 52 | } 53 | 54 | -(IBAction)toolItemClicked:(id)sender{ 55 | UIBarButtonItem *btn = (UIBarButtonItem *)sender; 56 | CUSRowLayout *layout = (CUSRowLayout *)self.contentView.layoutFrame; 57 | if(btn.tag == 0){ 58 | if(layout.type == CUSLayoutTypeHorizontal){ 59 | layout.type = CUSLayoutTypeVertical; 60 | [btn setTitle:@"HOR"]; 61 | }else{ 62 | layout.type = CUSLayoutTypeHorizontal; 63 | [btn setTitle:@"VER"]; 64 | } 65 | }else if(btn.tag == 1){ 66 | layout.spacing -= 5; 67 | if(layout.spacing < 0){ 68 | layout.spacing = 0; 69 | } 70 | }else if(btn.tag == 2){ 71 | layout.spacing += 5; 72 | }else if(btn.tag == 3){ 73 | if(layout.pack){ 74 | layout.pack = NO; 75 | [btn setTitle:@" pack "]; 76 | }else{ 77 | layout.pack = YES; 78 | [btn setTitle:@"unpack"]; 79 | } 80 | }else if(btn.tag == 4){ 81 | if(layout.justify){ 82 | layout.justify = NO; 83 | [btn setTitle:@" just "]; 84 | }else{ 85 | layout.justify = YES; 86 | [btn setTitle:@"unjust"]; 87 | } 88 | }else if(btn.tag == 10){ 89 | NSArray *array = self.contentView.subviews; 90 | if(array && [array count] > 0){ 91 | UIView *lastView = [array lastObject]; 92 | [lastView removeFromSuperview]; 93 | } 94 | 95 | }else if(btn.tag == 11){ 96 | UIView *view = [CUSLayoutSampleFactory createControl]; 97 | [self.contentView addSubview:view]; 98 | } 99 | 100 | [self.contentView CUSLayout:YES]; 101 | } 102 | 103 | -(void)toolButtonClicked{ 104 | if (self.scrollView.contentOffset.x == 0) { 105 | [self.scrollView setContentOffset:CGPointMake(self.scrollView.frame.size.width, 0) animated:YES]; 106 | }else{ 107 | [self.scrollView setContentOffset:CGPointMake(0, 0) animated:YES]; 108 | } 109 | } 110 | @end 111 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/advanced/CUSTableLayoutSampleViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CUSTableLayoutSampleViewController.h 3 | // CUSLayout 4 | // 5 | // Created by zhangyu on 13-4-16. 6 | // Copyright (c) 2013年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CUSLayoutSampleFactory.h" 11 | @interface CUSTableLayoutSampleViewController : CUSViewController 12 | @property (nonatomic,strong) IBOutlet UIView *contentView; 13 | @property (nonatomic,strong) IBOutlet UIScrollView *scrollView; 14 | -(IBAction)toolItemClicked:(id)sender; 15 | @end 16 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/advanced/CUSTableLayoutSampleViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSTableLayoutSampleViewController.m 3 | // CUSLayout 4 | // 5 | // Created by zhangyu on 13-4-16. 6 | // Copyright (c) 2013年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSTableLayoutSampleViewController.h" 10 | @implementation CUSTableLayoutSampleViewController{ 11 | NSMutableArray *colums; 12 | NSMutableArray *rows; 13 | } 14 | @synthesize contentView; 15 | @synthesize scrollView; 16 | 17 | //rotation 18 | -(void)viewDidLayoutSubviews{ 19 | [super viewDidLayoutSubviews]; 20 | 21 | self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 2, 44); 22 | [self.scrollView CUSLayout]; 23 | } 24 | //for ipad of ios4 25 | -(void)viewWillAppear:(BOOL)animated{ 26 | [super viewWillAppear:animated]; 27 | self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 2, 44); 28 | [self.scrollView CUSLayout]; 29 | } 30 | - (void)viewDidLoad{ 31 | [super viewDidLoad]; 32 | 33 | NSInteger controlCounter = 13; 34 | for (int i = 0; i < controlCounter; i++) { 35 | UIView *button = [CUSLayoutSampleFactory createControl:[NSString stringWithFormat:@"button%i",i]]; 36 | [self.contentView addSubview:button]; 37 | } 38 | 39 | // NSMutableArray *colums = [NSMutableArray array]; 40 | // [colums addObject:[CUSValue valueWithPercent:0.10]]; 41 | // [colums addObject:[CUSValue valueWithFloat:50]]; 42 | // [colums addObject:[CUSValue valueWithPercent:0.20]]; 43 | // [colums addObject:[CUSValue valueWithDefault]]; 44 | // 45 | // NSMutableArray *rows = [NSMutableArray array]; 46 | // [rows addObject:[CUSValue valueWithFloat:100]]; 47 | // [rows addObject:[CUSValue valueWithDefault]]; 48 | // [rows addObject:[CUSValue valueWithPercent:0.30]]; 49 | // [rows addObject:[CUSValue valueWithPercent:0.20]]; 50 | 51 | colums = [NSMutableArray array]; 52 | for (int i = 0 ; i < 4; i++) { 53 | [colums addObject:[CUSValue valueWithPercent:0.25]]; 54 | } 55 | rows = [NSMutableArray array]; 56 | for (int i = 0 ; i < 4; i++) { 57 | [rows addObject:[CUSValue valueWithPercent:0.25]]; 58 | } 59 | 60 | CUSTableLayout *layout = [[CUSTableLayout alloc]initWithcolumns:colums rows:rows]; 61 | 62 | [layout merge:1 row:1 colspan:2 rowspan:2]; 63 | self.contentView.layoutFrame = layout; 64 | 65 | self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 2, 44); 66 | CUSFillLayout *fillLayout = [[CUSFillLayout alloc]init]; 67 | fillLayout.spacing = 0; 68 | self.scrollView.layoutFrame = fillLayout; 69 | 70 | UIBarButtonItem *toolButton = [[UIBarButtonItem alloc]initWithTitle:@"tool" style:UIBarButtonItemStyleBordered target:self action:@selector(toolButtonClicked)]; 71 | self.navigationItem.rightBarButtonItem = toolButton; 72 | } 73 | 74 | -(IBAction)toolItemClicked:(id)sender{ 75 | UIBarButtonItem *btn = (UIBarButtonItem *)sender; 76 | CUSTableLayout *layout = (CUSTableLayout *)self.contentView.layoutFrame; 77 | if(btn.tag == 1){ 78 | layout.spacing -= 5; 79 | if(layout.spacing < 0){ 80 | layout.spacing = 0; 81 | } 82 | }else if(btn.tag == 2){ 83 | layout.spacing += 5; 84 | }else if(btn.tag == 3){ 85 | if([colums count] > 0){ 86 | [colums removeLastObject]; 87 | self.contentView.layoutFrame = [self createNewTableLayoutByOld:layout]; 88 | } 89 | }else if(btn.tag == 4){ 90 | [colums addObject:[CUSValue valueWithPercent:0.25]]; 91 | self.contentView.layoutFrame = [self createNewTableLayoutByOld:layout]; 92 | }else if(btn.tag == 5){ 93 | if([rows count] > 0){ 94 | [rows removeLastObject]; 95 | self.contentView.layoutFrame = [self createNewTableLayoutByOld:layout]; 96 | } 97 | }else if(btn.tag == 6){ 98 | [rows addObject:[CUSValue valueWithPercent:0.25]]; 99 | self.contentView.layoutFrame = [self createNewTableLayoutByOld:layout]; 100 | }else if(btn.tag == 10){ 101 | NSArray *array = self.contentView.subviews; 102 | if(array && [array count] > 0){ 103 | UIView *lastView = [array lastObject]; 104 | [lastView removeFromSuperview]; 105 | } 106 | }else if(btn.tag == 11){ 107 | UIView *view = [CUSLayoutSampleFactory createControl:[NSString stringWithFormat:@"button%i",(int)[self.contentView.subviews count]]]; 108 | [self.contentView addSubview:view]; 109 | } 110 | 111 | [self.contentView CUSLayout:YES]; 112 | } 113 | 114 | -(CUSTableLayout *)createNewTableLayoutByOld:(CUSTableLayout *)oldLayout{ 115 | CUSTableLayout *newLayout = [[CUSTableLayout alloc]initWithcolumns:colums rows:rows]; 116 | newLayout.spacing = oldLayout.spacing; 117 | return newLayout; 118 | } 119 | 120 | -(void)toolButtonClicked{ 121 | if (self.scrollView.contentOffset.x == 0) { 122 | [self.scrollView setContentOffset:CGPointMake(self.scrollView.frame.size.width, 0) animated:YES]; 123 | }else{ 124 | [self.scrollView setContentOffset:CGPointMake(0, 0) animated:YES]; 125 | } 126 | } 127 | @end 128 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/advanced/CUSTableLayoutSampleViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/base/CUSFillLayoutSampleViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CUSFillLayoutSampleViewController.h 3 | // CUSLayout 4 | // 5 | // Created by zhangyu on 13-4-9. 6 | // Copyright (c) 2013年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CUSLayout.h" 11 | #import "CUSLayoutSampleFactory.h" 12 | @interface CUSFillLayoutSampleViewController : CUSViewController 13 | @property (nonatomic,strong) IBOutlet UIView *contentView; 14 | 15 | 16 | -(IBAction)toolItemClicked:(id)sender; 17 | @end 18 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/base/CUSFillLayoutSampleViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSFillLayoutSampleViewController.m 3 | // CUSLayout 4 | // 5 | // Created by zhangyu on 13-4-9. 6 | // Copyright (c) 2013年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSFillLayoutSampleViewController.h" 10 | 11 | @implementation CUSFillLayoutSampleViewController 12 | @synthesize contentView; 13 | 14 | - (void)viewDidLoad{ 15 | [super viewDidLoad]; 16 | 17 | for (int i = 0; i < 4; i++) { 18 | 19 | UIView *view = [CUSLayoutSampleFactory createControl:[NSString stringWithFormat:@"button%i",i]]; 20 | [self.contentView addSubview:view]; 21 | } 22 | CUSFillLayout *layout = [[CUSFillLayout alloc]init]; 23 | self.contentView.layoutFrame = layout; 24 | 25 | // CUSLinearLayout *viewLayout = [[CUSLinearLayout alloc]init]; 26 | // viewLayout.spacing = 0; 27 | // self.view.layoutFrame = viewLayout; 28 | 29 | } 30 | 31 | -(IBAction)toolItemClicked:(id)sender{ 32 | UIBarButtonItem *btn = (UIBarButtonItem *)sender; 33 | CUSFillLayout *layout = (CUSFillLayout *)self.contentView.layoutFrame; 34 | if(btn.tag == 0){ 35 | if(layout.type == CUSLayoutTypeHorizontal){ 36 | layout.type = CUSLayoutTypeVertical; 37 | [btn setTitle:@"HOR"]; 38 | }else{ 39 | layout.type = CUSLayoutTypeHorizontal; 40 | [btn setTitle:@"VER"]; 41 | } 42 | }else if(btn.tag == 1){ 43 | layout.spacing -= 5; 44 | if(layout.spacing < 0){ 45 | layout.spacing = 0; 46 | } 47 | }else if(btn.tag == 2){ 48 | layout.spacing += 5; 49 | }else if(btn.tag == 3){ 50 | NSArray *array = self.contentView.subviews; 51 | if(array && [array count] > 0){ 52 | UIView *lastView = [array lastObject]; 53 | [lastView removeFromSuperview]; 54 | } 55 | 56 | }else if(btn.tag == 4){ 57 | UIView *view = [CUSLayoutSampleFactory createControl:[NSString stringWithFormat:@"button%i",(int)[self.contentView.subviews count]]]; 58 | [self.contentView addSubview:view]; 59 | } 60 | 61 | [self.contentView CUSLayout:YES]; 62 | } 63 | @end 64 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/base/CUSFillLayoutSampleViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1552 5 | 11G63 6 | 3084 7 | 1138.51 8 | 569.00 9 | 10 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 11 | 2083 12 | 13 | 14 | IBProxyObject 15 | IBUIBarButtonItem 16 | IBUIToolbar 17 | IBUIView 18 | 19 | 20 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 21 | 22 | 23 | PluginDependencyRecalculationVersion 24 | 25 | 26 | 27 | 28 | IBFilesOwner 29 | IBCocoaTouchFramework 30 | 31 | 32 | IBFirstResponder 33 | IBCocoaTouchFramework 34 | 35 | 36 | 37 | 274 38 | 39 | 40 | 41 | 266 42 | {{0, 460}, {320, 44}} 43 | 44 | 45 | _NS:9 46 | NO 47 | NO 48 | IBCocoaTouchFramework 49 | 50 | 51 | VER 52 | IBCocoaTouchFramework 53 | 1 54 | 55 | 56 | 57 | 1 58 | space- 59 | IBCocoaTouchFramework 60 | 1 61 | 62 | 63 | 64 | 2 65 | space+ 66 | IBCocoaTouchFramework 67 | 1 68 | 69 | 70 | 71 | 3 72 | view- 73 | IBCocoaTouchFramework 74 | 1 75 | 76 | 77 | 78 | 4 79 | view+ 80 | IBCocoaTouchFramework 81 | 1 82 | 83 | 84 | 85 | 86 | 87 | 88 | 274 89 | {320, 460} 90 | 91 | 92 | 93 | _NS:9 94 | 95 | 3 96 | MQA 97 | 98 | 2 99 | 100 | 101 | NO 102 | IBCocoaTouchFramework 103 | 104 | 105 | {{0, 64}, {320, 504}} 106 | 107 | 108 | 109 | 110 | 3 111 | MQA 112 | 113 | 114 | 115 | 116 | NO 117 | 118 | 119 | IBUIScreenMetrics 120 | 121 | YES 122 | 123 | 124 | 125 | 126 | 127 | {320, 568} 128 | {568, 320} 129 | 130 | 131 | IBCocoaTouchFramework 132 | Retina 4 Full Screen 133 | 2 134 | 135 | IBCocoaTouchFramework 136 | 137 | 138 | 139 | 140 | 141 | 142 | view 143 | 144 | 145 | 146 | 3 147 | 148 | 149 | 150 | contentView 151 | 152 | 153 | 154 | 36 155 | 156 | 157 | 158 | toolItemClicked: 159 | 160 | 161 | 162 | 17 163 | 164 | 165 | 166 | toolItemClicked: 167 | 168 | 169 | 170 | 30 171 | 172 | 173 | 174 | toolItemClicked: 175 | 176 | 177 | 178 | 31 179 | 180 | 181 | 182 | toolItemClicked: 183 | 184 | 185 | 186 | 34 187 | 188 | 189 | 190 | toolItemClicked: 191 | 192 | 193 | 194 | 35 195 | 196 | 197 | 198 | 199 | 200 | 0 201 | 202 | 203 | 204 | 205 | 206 | 1 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | -1 216 | 217 | 218 | File's Owner 219 | 220 | 221 | -2 222 | 223 | 224 | 225 | 226 | 4 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 5 239 | 240 | 241 | 242 | 243 | 10 244 | 245 | 246 | 247 | 248 | 28 249 | 250 | 251 | 252 | 253 | 29 254 | 255 | 256 | 257 | 258 | 32 259 | 260 | 261 | 262 | 263 | 33 264 | 265 | 266 | 267 | 268 | 269 | 270 | CUSFillLayoutSampleViewController 271 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 272 | UIResponder 273 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 274 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 275 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 276 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 277 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 278 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 279 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 280 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 281 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 282 | 283 | 284 | 285 | 286 | 287 | 36 288 | 289 | 290 | 291 | 292 | CUSFillLayoutSampleViewController 293 | UIViewController 294 | 295 | toolItemClicked: 296 | id 297 | 298 | 299 | toolItemClicked: 300 | 301 | toolItemClicked: 302 | id 303 | 304 | 305 | 306 | contentView 307 | UIView 308 | 309 | 310 | contentView 311 | 312 | contentView 313 | UIView 314 | 315 | 316 | 317 | IBProjectSource 318 | ./Classes/CUSFillLayoutSampleViewController.h 319 | 320 | 321 | 322 | 323 | 0 324 | IBCocoaTouchFramework 325 | YES 326 | 3 327 | 2083 328 | 329 | 330 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/base/CUSLinearLayoutSampleViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CUSLinearLayoutSampleViewController.h 3 | // CUSLayout 4 | // 5 | // Created by zhangyu on 13-4-16. 6 | // Copyright (c) 2013年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CUSLayoutSampleFactory.h" 11 | @interface CUSLinearLayoutSampleViewController : CUSViewController 12 | @property (nonatomic,strong) IBOutlet UIView *contentView; 13 | 14 | -(IBAction)toolItemClicked:(id)sender; 15 | @end 16 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/base/CUSLinearLayoutSampleViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSLinearLayoutSampleViewController.m 3 | // CUSLayout 4 | // 5 | // Created by zhangyu on 13-4-16. 6 | // Copyright (c) 2013年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSLinearLayoutSampleViewController.h" 10 | 11 | @implementation CUSLinearLayoutSampleViewController 12 | @synthesize contentView; 13 | 14 | - (void)viewDidLoad{ 15 | [super viewDidLoad]; 16 | 17 | NSInteger controlCounter = 3; 18 | for (int i = 0; i < controlCounter; i++) { 19 | UIView *button = [CUSLayoutSampleFactory createControl:[NSString stringWithFormat:@"button%i",i]]; 20 | if(i == controlCounter - 2){ 21 | CUSLinearData *layoutData = [[CUSLinearData alloc]init]; 22 | layoutData.fill = YES; 23 | button.layoutData = layoutData; 24 | }else{ 25 | button.layoutData = CUSLAYOUT.share_linearData; 26 | } 27 | [self.contentView addSubview:button]; 28 | 29 | 30 | } 31 | CUSLinearLayout *layout = [[CUSLinearLayout alloc]init]; 32 | self.contentView.layoutFrame = layout; 33 | } 34 | 35 | -(IBAction)toolItemClicked:(id)sender{ 36 | UIBarButtonItem *btn = (UIBarButtonItem *)sender; 37 | CUSLinearLayout *layout = (CUSLinearLayout *)self.contentView.layoutFrame; 38 | if(btn.tag == 0){ 39 | if(layout.type == CUSLayoutTypeHorizontal){ 40 | layout.type = CUSLayoutTypeVertical; 41 | [btn setTitle:@"HOR"]; 42 | }else{ 43 | layout.type = CUSLayoutTypeHorizontal; 44 | [btn setTitle:@"VER"]; 45 | } 46 | }else if(btn.tag == 1){ 47 | layout.spacing -= 5; 48 | if(layout.spacing < 0){ 49 | layout.spacing = 0; 50 | } 51 | }else if(btn.tag == 2){ 52 | layout.spacing += 5; 53 | }else if(btn.tag == 3){ 54 | NSArray *array = self.contentView.subviews; 55 | if(array && [array count] > 0){ 56 | UIView *lastView = [array lastObject]; 57 | [lastView removeFromSuperview]; 58 | } 59 | 60 | }else if(btn.tag == 4){ 61 | UIView *view = [CUSLayoutSampleFactory createControl:[NSString stringWithFormat:@"button%i",(int)[self.contentView.subviews count]]]; 62 | [self.contentView addSubview:view]; 63 | } 64 | 65 | [self.contentView CUSLayout:YES]; 66 | } 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/base/CUSLinearLayoutSampleViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1552 5 | 11G63 6 | 3084 7 | 1138.51 8 | 569.00 9 | 10 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 11 | 2083 12 | 13 | 14 | IBProxyObject 15 | IBUIBarButtonItem 16 | IBUIToolbar 17 | IBUIView 18 | 19 | 20 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 21 | 22 | 23 | PluginDependencyRecalculationVersion 24 | 25 | 26 | 27 | 28 | IBFilesOwner 29 | IBCocoaTouchFramework 30 | 31 | 32 | IBFirstResponder 33 | IBCocoaTouchFramework 34 | 35 | 36 | 37 | 274 38 | 39 | 40 | 41 | 274 42 | {320, 460} 43 | 44 | 45 | 46 | _NS:9 47 | 48 | 3 49 | MQA 50 | 51 | 2 52 | 53 | 54 | IBCocoaTouchFramework 55 | 56 | 57 | 58 | 266 59 | {{0, 460}, {320, 44}} 60 | 61 | 62 | 63 | _NS:9 64 | NO 65 | NO 66 | IBCocoaTouchFramework 67 | 68 | 69 | VER 70 | IBCocoaTouchFramework 71 | 1 72 | 73 | 74 | 75 | 1 76 | space- 77 | IBCocoaTouchFramework 78 | 1 79 | 80 | 81 | 82 | 2 83 | space+ 84 | IBCocoaTouchFramework 85 | 1 86 | 87 | 88 | 89 | 3 90 | view- 91 | IBCocoaTouchFramework 92 | 1 93 | 94 | 95 | 96 | 4 97 | view+ 98 | IBCocoaTouchFramework 99 | 1 100 | 101 | 102 | 103 | 104 | 105 | {{0, 64}, {320, 504}} 106 | 107 | 108 | 109 | 110 | 3 111 | MQA 112 | 113 | 114 | 115 | 116 | NO 117 | 118 | 119 | IBUIScreenMetrics 120 | 121 | YES 122 | 123 | 124 | 125 | 126 | 127 | {320, 568} 128 | {568, 320} 129 | 130 | 131 | IBCocoaTouchFramework 132 | Retina 4 Full Screen 133 | 2 134 | 135 | IBCocoaTouchFramework 136 | 137 | 138 | 139 | 140 | 141 | 142 | view 143 | 144 | 145 | 146 | 3 147 | 148 | 149 | 150 | contentView 151 | 152 | 153 | 154 | 30 155 | 156 | 157 | 158 | toolItemClicked: 159 | 160 | 161 | 162 | 45 163 | 164 | 165 | 166 | toolItemClicked: 167 | 168 | 169 | 170 | 44 171 | 172 | 173 | 174 | toolItemClicked: 175 | 176 | 177 | 178 | 43 179 | 180 | 181 | 182 | toolItemClicked: 183 | 184 | 185 | 186 | 48 187 | 188 | 189 | 190 | toolItemClicked: 191 | 192 | 193 | 194 | 49 195 | 196 | 197 | 198 | 199 | 200 | 0 201 | 202 | 203 | 204 | 205 | 206 | 1 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | -1 216 | 217 | 218 | File's Owner 219 | 220 | 221 | -2 222 | 223 | 224 | 225 | 226 | 4 227 | 228 | 229 | 230 | 231 | 32 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 33 244 | 245 | 246 | 247 | 248 | 34 249 | 250 | 251 | 252 | 253 | 35 254 | 255 | 256 | 257 | 258 | 46 259 | 260 | 261 | 262 | 263 | 47 264 | 265 | 266 | 267 | 268 | 269 | 270 | CUSLinnerLayoutSampleViewController 271 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 272 | UIResponder 273 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 274 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 275 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 276 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 277 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 278 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 279 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 280 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 281 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 282 | 283 | 284 | 285 | 286 | 287 | 49 288 | 289 | 290 | 291 | 292 | CUSLinnerLayoutSampleViewController 293 | UIViewController 294 | 295 | toolItemClicked: 296 | id 297 | 298 | 299 | toolItemClicked: 300 | 301 | toolItemClicked: 302 | id 303 | 304 | 305 | 306 | contentView 307 | UIView 308 | 309 | 310 | contentView 311 | 312 | contentView 313 | UIView 314 | 315 | 316 | 317 | IBProjectSource 318 | ./Classes/CUSLinnerLayoutSampleViewController.h 319 | 320 | 321 | 322 | 323 | 0 324 | IBCocoaTouchFramework 325 | YES 326 | 3 327 | 2083 328 | 329 | 330 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/base/CUSStackLayoutSampleViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CUSStackLayoutSampleViewController.h 3 | // CUSLayout 4 | // 5 | // Created by zhangyu on 13-5-22. 6 | // 7 | // 8 | 9 | #import 10 | #import "CUSLayout.h" 11 | #import "CUSLayoutSampleFactory.h" 12 | 13 | @interface CUSStackLayoutSampleViewController : CUSViewController 14 | @property (nonatomic,strong) IBOutlet UIView *contentView; 15 | 16 | 17 | -(IBAction)toolItemClicked:(id)sender; 18 | @end 19 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/base/CUSStackLayoutSampleViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSStackLayoutSampleViewController.m 3 | // CUSLayout 4 | // 5 | // Created by zhangyu on 13-5-22. 6 | // 7 | // 8 | 9 | #import "CUSStackLayoutSampleViewController.h" 10 | 11 | @implementation CUSStackLayoutSampleViewController 12 | @synthesize contentView; 13 | 14 | - (void)viewDidLoad{ 15 | [super viewDidLoad]; 16 | 17 | for (int i = 0; i < 4; i++) { 18 | UIView *view = [CUSLayoutSampleFactory createControl:[NSString stringWithFormat:@"button%i",i]]; 19 | view.alpha = 0.5; 20 | [self.contentView addSubview:view]; 21 | } 22 | CUSStackLayout *layout = [[CUSStackLayout alloc]init]; 23 | self.contentView.layoutFrame = layout; 24 | } 25 | 26 | -(IBAction)toolItemClicked:(id)sender{ 27 | UIBarButtonItem *btn = (UIBarButtonItem *)sender; 28 | CUSStackLayout *layout = (CUSStackLayout *)self.contentView.layoutFrame; 29 | if(btn.tag == 0){ 30 | layout.showViewIndex++; 31 | if(layout.showViewIndex >= [self.contentView.subviews count]){ 32 | layout.showViewIndex = 0; 33 | } 34 | [self.contentView CUSLayout:YES]; 35 | 36 | //You could use the next code to design animation by you self 37 | /* 38 | [self.contentView CUSLayout]; 39 | [UIView beginAnimations:@"animation" context:nil]; 40 | [UIView setAnimationDuration:0.5f]; 41 | [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 42 | [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.contentView cache:YES]; 43 | [UIView commitAnimations]; 44 | */ 45 | }else if(btn.tag == 11){ 46 | NSArray *array = self.contentView.subviews; 47 | if(array && [array count] > 0){ 48 | UIView *lastView = [array lastObject]; 49 | [lastView removeFromSuperview]; 50 | } 51 | [self.contentView CUSLayout]; 52 | }else if(btn.tag == 12){ 53 | UIView *view = [CUSLayoutSampleFactory createControl:[NSString stringWithFormat:@"button%i",(int)[self.contentView.subviews count]]]; 54 | view.alpha = 0.5; 55 | [self.contentView addSubview:view]; 56 | [self.contentView CUSLayout]; 57 | }else if(btn.tag == 13){ 58 | if (layout.hideOther) { 59 | [btn setTitle:@"showOther"]; 60 | }else{ 61 | [btn setTitle:@"hideOther"]; 62 | } 63 | layout.hideOther = !layout.hideOther; 64 | [self.contentView CUSLayout]; 65 | } 66 | } 67 | @end -------------------------------------------------------------------------------- /CUSLayoutExample/controller/base/CUSStackLayoutSampleViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/exampleCommon/CUSAboutViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CUSAboutViewController.h 3 | // CUSLayout 4 | // 5 | // Created by zhangyu on 13-4-22. 6 | // Copyright (c) 2013年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CUSViewController.h" 11 | @interface CUSAboutViewController : CUSViewController 12 | @property (nonatomic,strong) IBOutlet UITableView *table; 13 | @property (nonatomic,strong) NSMutableArray *dataItems; 14 | @end 15 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/exampleCommon/CUSAboutViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSAboutViewController.m 3 | // CUSLayout 4 | // 5 | // Created by zhangyu on 13-4-22. 6 | // Copyright (c) 2013年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSAboutViewController.h" 10 | #import "CUSLayout.h" 11 | @implementation CUSAboutViewController 12 | @synthesize table; 13 | @synthesize dataItems; 14 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 15 | { 16 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 17 | if (self) { 18 | self.title = @"About"; 19 | self.dataItems = [NSMutableArray array]; 20 | [self.dataItems addObject:[NSArray arrayWithObjects:@"Author:",@"zhangyu", nil]]; 21 | [self.dataItems addObject:[NSArray arrayWithObjects:@"Version:",@"1.0", nil]]; 22 | [self.dataItems addObject:[NSArray arrayWithObjects:@"e-mail:",@"cuslayout@163.com", nil]]; 23 | [self.dataItems addObject:[NSArray arrayWithObjects:@"Blog",@"http://weibo.com/cuslayout", nil]]; 24 | } 25 | return self; 26 | } 27 | 28 | - (void)viewDidLoad 29 | { 30 | [super viewDidLoad]; 31 | 32 | NSString *txtPath = [[NSBundle mainBundle] pathForResource:@"README" ofType:@"txt"]; 33 | NSString *string = [[NSString alloc] initWithContentsOfFile:txtPath encoding:NSUTF8StringEncoding error:nil]; 34 | 35 | CGRect labelframe = CGRectMake(0, 0, 300, 550); 36 | UIView *labelContainer = [[UIView alloc]initWithFrame:labelframe]; 37 | CUSFillLayout *layout = [[CUSFillLayout alloc]init]; 38 | layout.marginLeft = layout.marginRight = 10; 39 | layout.marginTop = layout.marginBottom = 10; 40 | labelContainer.layoutFrame = layout; 41 | 42 | UILabel *label = [[UILabel alloc] init]; 43 | label.text=string; 44 | label.backgroundColor = [UIColor clearColor]; 45 | label.textAlignment = UITextAlignmentLeft; 46 | label.lineBreakMode = UILineBreakModeCharacterWrap; 47 | label.numberOfLines = 0; 48 | [labelContainer addSubview:label]; 49 | self.table.tableHeaderView = labelContainer; 50 | 51 | } 52 | 53 | - (void)didReceiveMemoryWarning 54 | { 55 | [super didReceiveMemoryWarning]; 56 | // Dispose of any resources that can be recreated. 57 | } 58 | 59 | #pragma mark - Table view data source 60 | 61 | -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ 62 | return @"Contact Us"; 63 | } 64 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 65 | { 66 | return 1; 67 | } 68 | 69 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 70 | { 71 | return [self.dataItems count]; 72 | } 73 | 74 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 75 | return 44; 76 | } 77 | 78 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 79 | { 80 | static NSString *CellIdentifier = @"Cell"; 81 | 82 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 83 | if (cell == nil) { 84 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; 85 | } 86 | NSArray *array = [self.dataItems objectAtIndex:indexPath.row]; 87 | if (array && [array count] >= 1) { 88 | cell.textLabel.text = [array objectAtIndex:0]; 89 | cell.detailTextLabel.text = [array objectAtIndex:1]; 90 | } 91 | 92 | return cell; 93 | } 94 | 95 | @end 96 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/exampleCommon/CUSAboutViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1552 5 | 11G63 6 | 3084 7 | 1138.51 8 | 569.00 9 | 10 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 11 | 2083 12 | 13 | 14 | IBProxyObject 15 | IBUITableView 16 | IBUIView 17 | 18 | 19 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 20 | 21 | 22 | PluginDependencyRecalculationVersion 23 | 24 | 25 | 26 | 27 | IBFilesOwner 28 | IBCocoaTouchFramework 29 | 30 | 31 | IBFirstResponder 32 | IBCocoaTouchFramework 33 | 34 | 35 | 36 | 274 37 | 38 | 39 | 40 | 274 41 | {320, 504} 42 | 43 | 44 | _NS:9 45 | 46 | 1 47 | MCAwIDAgMAA 48 | groupTableViewBackgroundColor 49 | 50 | YES 51 | IBCocoaTouchFramework 52 | YES 53 | 1 54 | 2 55 | 0 56 | YES 57 | 44 58 | 10 59 | 10 60 | 61 | 62 | {{0, 64}, {320, 504}} 63 | 64 | 65 | 66 | 67 | 3 68 | MQA 69 | 70 | 2 71 | 72 | 73 | 74 | 75 | NO 76 | 77 | 78 | IBUIScreenMetrics 79 | 80 | YES 81 | 82 | 83 | 84 | 85 | 86 | {320, 568} 87 | {568, 320} 88 | 89 | 90 | IBCocoaTouchFramework 91 | Retina 4 Full Screen 92 | 2 93 | 94 | IBCocoaTouchFramework 95 | 96 | 97 | 98 | 99 | 100 | 101 | view 102 | 103 | 104 | 105 | 3 106 | 107 | 108 | 109 | table 110 | 111 | 112 | 113 | 28 114 | 115 | 116 | 117 | dataSource 118 | 119 | 120 | 121 | 18 122 | 123 | 124 | 125 | delegate 126 | 127 | 128 | 129 | 19 130 | 131 | 132 | 133 | 134 | 135 | 0 136 | 137 | 138 | 139 | 140 | 141 | 1 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | -1 150 | 151 | 152 | File's Owner 153 | 154 | 155 | -2 156 | 157 | 158 | 159 | 160 | 13 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | CUSAboutViewController 169 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 170 | UIResponder 171 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 172 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 173 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 174 | 175 | 176 | 177 | 178 | 179 | 28 180 | 181 | 182 | 183 | 184 | CUSAboutViewController 185 | UIViewController 186 | 187 | table 188 | UITableView 189 | 190 | 191 | table 192 | 193 | table 194 | UITableView 195 | 196 | 197 | 198 | IBProjectSource 199 | ./Classes/CUSAboutViewController.h 200 | 201 | 202 | 203 | 204 | 0 205 | IBCocoaTouchFramework 206 | YES 207 | 3 208 | 2083 209 | 210 | 211 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/exampleCommon/CUSLayoutSampleFactory.h: -------------------------------------------------------------------------------- 1 | // 2 | // CUSLayoutSampleFactory.h 3 | // CUSLayout 4 | // 5 | // Created by zhangyu on 13-4-24. 6 | // 7 | // 8 | #import "CUSViewController.h" 9 | 10 | @interface CUSLayoutSampleFactory : NSObject 11 | 12 | +(UIView *)createControl; 13 | 14 | +(UIView *)createControl:(NSString *)title; 15 | +(UIColor *)randomLightingColor; 16 | @end 17 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/exampleCommon/CUSLayoutSampleFactory.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSLayoutSampleFactory.m 3 | // CUSLayout 4 | // 5 | // Created by zhangyu on 13-4-24. 6 | // 7 | // 8 | 9 | #import "CUSLayoutSampleFactory.h" 10 | #import 11 | @implementation CUSLayoutSampleFactory 12 | 13 | +(UIView *)createControl{ 14 | NSString *str = @"abcdefghijklmnopqrstuvwxyz"; 15 | NSInteger r = 1 + random()%15; 16 | NSString *title = [str substringToIndex:r]; 17 | 18 | return [CUSLayoutSampleFactory createControl:title]; 19 | } 20 | 21 | +(UIView *)createControl:(NSString *)title{ 22 | // UILabel *label = [[UILabel alloc] init]; 23 | UIButton *label = [UIButton buttonWithType:UIButtonTypeCustom]; 24 | // label.text=title; 25 | // label.textAlignment = UITextAlignmentCenter; 26 | 27 | [label setTitle:title forState:UIControlStateNormal]; 28 | label.backgroundColor = [CUSLayoutSampleFactory randomLightingColor]; 29 | label.layer.cornerRadius = 5; 30 | 31 | return label; 32 | } 33 | 34 | +(UIColor *)randomLightingColor{ 35 | int numberArray[3]; 36 | numberArray[0] = random()%255; 37 | numberArray[1] = random()%255; 38 | numberArray[2] = random()%255; 39 | 40 | // 41 | if(numberArray[0] + numberArray[1] < 40){ 42 | numberArray[2] = 125 + random()%125; 43 | } 44 | if(numberArray[0] + numberArray[1] + numberArray[2] > 235*3){ 45 | numberArray[2] = random()%125; 46 | } 47 | 48 | 49 | int i = random()%3; 50 | int t = numberArray[i]; 51 | numberArray[i] = numberArray[2 - i]; 52 | numberArray[2 - i] = t; 53 | 54 | CGFloat r = numberArray[0]/255.0f; 55 | CGFloat g = numberArray[1]/255.0f; 56 | CGFloat b = numberArray[2]/255.0f; 57 | return [UIColor colorWithRed:r green:g blue:b alpha:1]; 58 | } 59 | @end 60 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/exampleCommon/CUSMainViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CUSMainViewController.h 3 | // CUSPadFrameSample 4 | // 5 | // Created by zhangyu on 13-4-3. 6 | // Copyright (c) 2013年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CUSAboutViewController.h" 12 | 13 | @interface CUSMainViewController : CUSViewController 14 | @property(nonatomic,strong) NSMutableArray *dataItems; 15 | @end 16 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/exampleCommon/CUSMainViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSMainViewController.m 3 | // CUSPadFrameSample 4 | // 5 | // Created by zhangyu on 13-4-3. 6 | // Copyright (c) 2013年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSMainViewController.h" 10 | 11 | @implementation CUSMainViewController 12 | @synthesize dataItems; 13 | - (id)init 14 | { 15 | self = [super init]; 16 | if (self) { 17 | self.title = @"CUSLayout"; 18 | self.dataItems = [NSMutableArray array]; 19 | // 20 | NSMutableArray *groupArray0 = [NSMutableArray array]; 21 | [groupArray0 addObject:[NSArray arrayWithObjects:@"FillLayout",@"Simple, easy to use, efficient",@"CUSFillLayoutSampleViewController", nil]]; 22 | [groupArray0 addObject:[NSArray arrayWithObjects:@"StackLayout",@"Cascading Display",@"CUSStackLayoutSampleViewController", nil]]; 23 | [groupArray0 addObject:[NSArray arrayWithObjects:@"LinearLayout",@"Simple to HTML or LinearLayout in Android",@"CUSLinearLayoutSampleViewController", nil]]; 24 | [self.dataItems addObject:groupArray0]; 25 | 26 | NSMutableArray *groupArray1 = [NSMutableArray array]; 27 | [groupArray1 addObject:[NSArray arrayWithObjects:@"RowLayout",@"Layout in a row",@"CUSRowLayoutSampleViewController", nil]]; 28 | [groupArray1 addObject:[NSArray arrayWithObjects:@"TableLayout",@"Simple to HTML Table Tag Layout",@"CUSTableLayoutSampleViewController", nil]]; 29 | 30 | [groupArray1 addObject:[NSArray arrayWithObjects:@"GridLayout",@"Flat style? So easy",@"CUSGridLayoutSampleViewController", nil]]; 31 | 32 | 33 | [self.dataItems addObject:groupArray1]; 34 | 35 | NSMutableArray *groupArray2 = [NSMutableArray array]; 36 | [groupArray2 addObject:[NSArray arrayWithObjects:@"LayoutManager",@"Long press to drag",@"CUSLayoutManagerSampleViewController", nil]]; 37 | [self.dataItems addObject:groupArray2]; 38 | 39 | NSMutableArray *groupArray3 = [NSMutableArray array]; 40 | [groupArray3 addObject:[NSArray arrayWithObjects:@"Single View Fill",@"",@"CUSSingleViewFillViewController", nil]]; 41 | [groupArray3 addObject:[NSArray arrayWithObjects:@"Tow View Divided",@"",@"CUSTowViewDividedViewController", nil]]; 42 | [groupArray3 addObject:[NSArray arrayWithObjects:@"Three View Extend",@"",@"CUSThreeViewExtendViewController", nil]]; 43 | [groupArray3 addObject:[NSArray arrayWithObjects:@"Scroll Flow View",@"",@"CUSFlowViewController", nil]]; 44 | [groupArray3 addObject:[NSArray arrayWithObjects:@"Multi View Divided",@"",@"CUSMultiViewDividedViewController", nil]]; 45 | [groupArray3 addObject:[NSArray arrayWithObjects:@"Waterfall",@"",@"CUSWaterfallViewController", nil]]; 46 | 47 | [groupArray3 addObject:[NSArray arrayWithObjects:@"9 Grid",@"",@"CUS9GridViewController", nil]]; 48 | 49 | [groupArray3 addObject:[NSArray arrayWithObjects:@"click move",@"",@"CUSPassViewController", nil]]; 50 | [self.dataItems addObject:groupArray3]; 51 | 52 | 53 | } 54 | return self; 55 | } 56 | 57 | - (void)viewDidLoad{ 58 | [super viewDidLoad]; 59 | 60 | UITableView *talbeView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped]; 61 | talbeView.dataSource = self; 62 | talbeView.delegate = self; 63 | 64 | [self.view addSubview:talbeView]; 65 | self.view.layoutFrame = CUSLAYOUT.share_fillLayout_H; 66 | 67 | UIBarButtonItem *aboutButton = [[UIBarButtonItem alloc]initWithTitle:@"about" style:UIBarButtonItemStyleBordered target:self action:@selector(aboutButtonClicked)]; 68 | self.navigationItem.rightBarButtonItem = aboutButton; 69 | } 70 | 71 | - (void)aboutButtonClicked{ 72 | CUSAboutViewController *nextController = [[CUSAboutViewController alloc]initWithNibName:@"CUSAboutViewController" bundle:nil]; 73 | [self.navigationController pushViewController:nextController animated:YES]; 74 | } 75 | 76 | #pragma mark - Table view data source 77 | 78 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ 79 | return [self.dataItems count]; 80 | } 81 | 82 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 83 | NSArray *sectionArray = [self.dataItems objectAtIndex:section]; 84 | return [sectionArray count]; 85 | } 86 | 87 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 88 | return 44; 89 | } 90 | 91 | -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ 92 | if (section == 0) { 93 | return @"Base Layout"; 94 | }else if (section == 1) { 95 | return @"Advance Layout"; 96 | }else if (section == 2) { 97 | return @"Other"; 98 | }else if (section == 3) { 99 | return @"Typical"; 100 | }else{ 101 | return @""; 102 | } 103 | } 104 | 105 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 106 | static NSString *CellIdentifier = @"Cell"; 107 | 108 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 109 | if (cell == nil) { 110 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 111 | } 112 | NSArray *sectionArray = [self.dataItems objectAtIndex:indexPath.section]; 113 | NSArray *array = [sectionArray objectAtIndex:indexPath.row]; 114 | if (array && [array count] >= 1) { 115 | cell.textLabel.text = [array objectAtIndex:0]; 116 | cell.detailTextLabel.text = [array objectAtIndex:1]; 117 | } 118 | cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 119 | 120 | return cell; 121 | } 122 | 123 | -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 124 | NSArray *sectionArray = [self.dataItems objectAtIndex:indexPath.section]; 125 | NSArray *array = [sectionArray objectAtIndex:indexPath.row]; 126 | if (array && [array count] >= 2) { 127 | BOOL flag = [self loadViewWithClassName:[array objectAtIndex:2] title:[array objectAtIndex:0]]; 128 | if(!flag){ 129 | UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"notice" message:@"Not impletmented" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil]; 130 | [alert show]; 131 | } 132 | }else{ 133 | NSLog(@"dataItems error"); 134 | } 135 | } 136 | 137 | -(BOOL)loadViewWithClassName:(NSString*)name title:(NSString*)title { 138 | Class controllerClass=NSClassFromString(name); 139 | if(controllerClass){ 140 | UIViewController* nextController = nil; 141 | if ([self fileExist:name ofType:@"nib"]) { 142 | nextController = [[controllerClass alloc]initWithNibName:name bundle:nil]; 143 | }else{ 144 | nextController = [[controllerClass alloc]init]; 145 | } 146 | 147 | nextController.title = title; 148 | [self.navigationController pushViewController:nextController animated:YES]; 149 | return YES; 150 | } 151 | return NO; 152 | } 153 | 154 | -(BOOL)fileExist:(NSString *)fileName ofType:(NSString *)type{ 155 | NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:type]; 156 | NSFileManager *file_manager = [NSFileManager defaultManager]; 157 | return [file_manager fileExistsAtPath:path]; 158 | } 159 | 160 | @end 161 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/exampleCommon/CUSViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CUSViewController.h 3 | // CUSLayout 4 | // 5 | // Created by zhangyu on 14-2-21. 6 | // 7 | // 8 | 9 | #import 10 | #import "CUSLayout.h" 11 | @interface CUSViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/exampleCommon/CUSViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSViewController.m 3 | // CUSLayout 4 | // 5 | // Created by zhangyu on 14-2-21. 6 | // 7 | // 8 | 9 | #import "CUSViewController.h" 10 | 11 | @interface CUSViewController () 12 | 13 | @end 14 | 15 | @implementation CUSViewController 16 | 17 | - (void)viewDidLoad 18 | { 19 | [super viewDidLoad]; 20 | self.view.backgroundColor = [UIColor whiteColor]; 21 | #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 22 | if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { 23 | self.edgesForExtendedLayout = UIRectEdgeNone; 24 | self.extendedLayoutIncludesOpaqueBars = NO; 25 | self.modalPresentationCapturesStatusBarAppearance = NO; 26 | 27 | self.navigationController.navigationBar.translucent = NO; 28 | self.tabBarController.tabBar.translucent = NO; 29 | } 30 | #endif 31 | } 32 | 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/other/CUSLayoutManagerSampleViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CUSLayoutManagerSampleViewController.h 3 | // CUSLayout 4 | // 5 | // Created by zhangyu on 13-5-20. 6 | // 7 | // 8 | 9 | #import 10 | #import "CUSLayoutSampleFactory.h" 11 | @interface CUSLayoutManagerSampleViewController : CUSViewController 12 | 13 | @property (nonatomic,strong) CUSLayoutDesignerView * designerView; 14 | @end 15 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/other/CUSLayoutManagerSampleViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSLayoutManagerSampleViewController.m 3 | // CUSLayout 4 | // 5 | // Created by zhangyu on 13-5-20. 6 | // 7 | // 8 | 9 | #import "CUSLayoutManagerSampleViewController.h" 10 | 11 | 12 | @implementation CUSLayoutManagerSampleViewController 13 | @synthesize designerView; 14 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 15 | { 16 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 17 | if (self) { 18 | 19 | } 20 | return self; 21 | } 22 | 23 | - (void)viewDidLoad 24 | { 25 | [super viewDidLoad]; 26 | 27 | self.designerView = [[CUSLayoutDesignerView alloc]init]; 28 | [self.view addSubview:self.designerView]; 29 | self.view.layoutFrame = CUSLAYOUT.share_fillLayout_H; 30 | 31 | NSInteger controlCounter = 13; 32 | for (int i = 0; i < controlCounter; i++) { 33 | UIView *button = [CUSLayoutSampleFactory createControl:[NSString stringWithFormat:@"Long press%i",i]]; 34 | [self.designerView addSubview:button]; 35 | } 36 | 37 | NSMutableArray *colums = [NSMutableArray array]; 38 | for (int i = 0 ; i < 4; i++) { 39 | [colums addObject:[CUSValue valueWithPercent:0.25]]; 40 | } 41 | NSMutableArray *rows = [NSMutableArray array]; 42 | for (int i = 0 ; i < 4; i++) { 43 | [rows addObject:[CUSValue valueWithPercent:0.25]]; 44 | } 45 | 46 | CUSTableLayout *layout = [[CUSTableLayout alloc]initWithcolumns:colums rows:rows]; 47 | 48 | [layout merge:1 row:1 colspan:2 rowspan:2]; 49 | self.designerView.layoutFrame = layout; 50 | } 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/other/CUSLayoutManagerSampleViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1536 5 | 12A269 6 | 2835 7 | 1187 8 | 624.00 9 | 10 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 11 | 1919 12 | 13 | 14 | IBProxyObject 15 | IBUIView 16 | 17 | 18 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 19 | 20 | 21 | PluginDependencyRecalculationVersion 22 | 23 | 24 | 25 | 26 | IBFilesOwner 27 | IBCocoaTouchFramework 28 | 29 | 30 | IBFirstResponder 31 | IBCocoaTouchFramework 32 | 33 | 34 | 35 | 274 36 | {{0, 20}, {320, 548}} 37 | 38 | 39 | 40 | 41 | 3 42 | MQA 43 | 44 | 2 45 | 46 | 47 | 48 | 49 | IBUIScreenMetrics 50 | 51 | YES 52 | 53 | 54 | 55 | 56 | 57 | {320, 568} 58 | {568, 320} 59 | 60 | 61 | IBCocoaTouchFramework 62 | Retina 4 Full Screen 63 | 2 64 | 65 | IBCocoaTouchFramework 66 | 67 | 68 | 69 | 70 | 71 | 72 | view 73 | 74 | 75 | 76 | 3 77 | 78 | 79 | 80 | 81 | 82 | 0 83 | 84 | 85 | 86 | 87 | 88 | 1 89 | 90 | 91 | 92 | 93 | -1 94 | 95 | 96 | File's Owner 97 | 98 | 99 | -2 100 | 101 | 102 | 103 | 104 | 105 | 106 | CUSLayoutManagerSampleViewController 107 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 108 | UIResponder 109 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 110 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 111 | 112 | 113 | 114 | 115 | 116 | 3 117 | 118 | 119 | 120 | 121 | CUSLayoutManagerSampleViewController 122 | UIViewController 123 | 124 | IBProjectSource 125 | ./Classes/CUSLayoutManagerSampleViewController.h 126 | 127 | 128 | 129 | 130 | 0 131 | IBCocoaTouchFramework 132 | YES 133 | 3 134 | YES 135 | 1919 136 | 137 | 138 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/typical/CUS9GridViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CUS9GridViewController.h 3 | // CUSLayoutExample 4 | // 5 | // Created by zhangyu on 14-6-11. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSTypicalCasesViewController.h" 10 | 11 | @interface CUS9GridViewController : CUSTypicalCasesViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/typical/CUS9GridViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUS9GridViewController.m 3 | // CUSLayoutExample 4 | // 5 | // Created by zhangyu on 14-6-11. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUS9GridViewController.h" 10 | 11 | @implementation CUS9GridViewController 12 | -(void)viewDidLoad{ 13 | [super viewDidLoad]; 14 | CUSGridLayout *layout = [[CUSGridLayout alloc]initWithNumColumns:3]; 15 | self.view.layoutFrame = layout; 16 | 17 | for (int i = 0; i < 9; i++) { 18 | UIView *view = [CUSLayoutSampleFactory createControl:[NSString stringWithFormat:@"%i",i]]; 19 | view.tag = i; 20 | CUSGridData *data = [[CUSGridData alloc]init]; 21 | data.grabExcessHorizontalSpace = YES; 22 | data.grabExcessVerticalSpace = YES; 23 | view.layoutData = data; 24 | [self.view addSubview:view]; 25 | } 26 | } 27 | 28 | @end -------------------------------------------------------------------------------- /CUSLayoutExample/controller/typical/CUSFlowViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CUSFlowViewController.h 3 | // CUSLayoutExample 4 | // 5 | // Created by zhangyu on 14-7-30. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSTypicalCasesViewController.h" 10 | 11 | @interface CUSFlowViewController : CUSTypicalCasesViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/typical/CUSFlowViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSFlowViewController.m 3 | // CUSLayoutExample 4 | // 5 | // Created by zhangyu on 14-7-30. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSFlowViewController.h" 10 | 11 | @interface CUSFlowViewController() 12 | @property(nonatomic,strong)UIScrollView *scrollView; 13 | @property(nonatomic,assign)NSInteger pageCounter; 14 | @end 15 | 16 | @implementation CUSFlowViewController 17 | @synthesize scrollView; 18 | @synthesize pageCounter; 19 | 20 | -(void)viewDidLoad{ 21 | [super viewDidLoad]; 22 | UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc]initWithTitle:@"add" style:UIBarButtonItemStyleBordered target:self action:@selector(buttonItemClicked)]; 23 | self.navigationItem.rightBarButtonItem = buttonItem; 24 | 25 | self.view.layoutFrame = CUSLAYOUT.share_fillLayout_V; 26 | scrollView = [[UIScrollView alloc]init]; 27 | scrollView.scrollEnabled = YES; 28 | scrollView.showsVerticalScrollIndicator = YES; 29 | scrollView.delegate = self; 30 | scrollView.layoutFrame = CUSLAYOUT.share_linearLayout_V; 31 | [self.view addSubview:scrollView]; 32 | [self addMoreControls]; 33 | 34 | 35 | } 36 | 37 | -(void)buttonItemClicked{ 38 | [self addMoreControls]; 39 | [scrollView CUSLayout:YES]; 40 | } 41 | 42 | -(void)addMoreControls{ 43 | UIView *subView = [CUSLayoutSampleFactory createControl:[NSString stringWithFormat:@"button %i",self.pageCounter]]; 44 | subView.frame = CGRectMake(0, -44, 320, 44); 45 | CUSLinearData *topData = [[CUSLinearData alloc]init]; 46 | topData.height = 44; 47 | subView.layoutData = topData; 48 | [scrollView addSubview:subView]; 49 | scrollView.contentSize = [scrollView computeSize:CGSizeMake(self.view.frame.size.width, -1)]; 50 | self.pageCounter++; 51 | } 52 | @end 53 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/typical/CUSMultiViewDividedViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CUSMultiViewDividedViewController.h 3 | // CUSLayoutExample 4 | // 5 | // Created by zhangyu on 14-6-11. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSTypicalCasesViewController.h" 10 | 11 | @interface CUSMultiViewDividedViewController : CUSTypicalCasesViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/typical/CUSMultiViewDividedViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSMultiViewDividedViewController.m 3 | // CUSLayoutExample 4 | // 5 | // Created by zhangyu on 14-6-11. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSMultiViewDividedViewController.h" 10 | 11 | @implementation CUSMultiViewDividedViewController 12 | -(void)viewDidLoad{ 13 | [super viewDidLoad]; 14 | 15 | self.view.layoutFrame = CUSLAYOUT.share_linearLayout_V; 16 | UIView *topView = [[UIView alloc]init]; 17 | CUSLinearData *topData = [[CUSLinearData alloc]init]; 18 | topData.height = 44; 19 | topView.layoutData = topData; 20 | [self.view addSubview:topView]; 21 | 22 | UIView *centerView = [CUSLayoutSampleFactory createControl:@"center"]; 23 | CUSLinearData *centerData = [[CUSLinearData alloc]init]; 24 | centerData.fill = YES; 25 | centerView.layoutData = centerData; 26 | [self.view addSubview:centerView]; 27 | 28 | topView.layoutFrame = CUSLAYOUT.share_fillLayout_H; 29 | for (int i = 0; i < 4; i++) { 30 | UIView *view = [CUSLayoutSampleFactory createControl:[NSString stringWithFormat:@"button%i",i]]; 31 | [topView addSubview:view]; 32 | } 33 | } 34 | @end 35 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/typical/CUSPassViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CUSPassViewController.h 3 | // CUSLayoutExample 4 | // 5 | // Created by zhangyu on 14-6-11. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSTypicalCasesViewController.h" 10 | 11 | @interface CUSPassViewController : CUSTypicalCasesViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/typical/CUSPassViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSPassViewController.m 3 | // CUSLayoutExample 4 | // 5 | // Created by zhangyu on 14-6-11. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSPassViewController.h" 10 | 11 | 12 | @interface CUSPassViewController() 13 | @property(nonatomic,strong)UIView *topView; 14 | @property(nonatomic,strong)UIView *bottomView; 15 | @end 16 | 17 | @implementation CUSPassViewController 18 | @synthesize topView; 19 | @synthesize bottomView; 20 | -(void)viewDidLoad{ 21 | [super viewDidLoad]; 22 | CUSLinearLayout *layout = [[CUSLinearLayout alloc]init]; 23 | self.view.layoutFrame = layout; 24 | CUSLinearData *fillData = [[CUSLinearData alloc]init]; 25 | fillData.fill = YES; 26 | CUSLinearData *centerData = [[CUSLinearData alloc]init]; 27 | centerData.height = 50; 28 | 29 | topView = [[UIView alloc]init]; 30 | topView.layoutData = fillData; 31 | [self.view addSubview:topView]; 32 | 33 | UILabel *centerView = [[UILabel alloc]init]; 34 | centerView.layoutData = centerData; 35 | centerView.textAlignment = NSTextAlignmentCenter; 36 | [centerView setText:@"touch the buttons"]; 37 | [centerView setFont:[UIFont systemFontOfSize:22]]; 38 | [self.view addSubview:centerView]; 39 | 40 | bottomView = [[UIView alloc]init]; 41 | bottomView.layoutData = fillData; 42 | [self.view addSubview:bottomView]; 43 | 44 | [self addControlsToView:topView withTag:0 withText:@"tpView"]; 45 | [self addControlsToView:bottomView withTag:1 withText:@"btView"]; 46 | } 47 | -(void)addControlsToView:(UIView *)parentView withTag:(NSInteger)tag withText:(NSString *)text{ 48 | CUSRowLayout *layout = [[CUSRowLayout alloc]init]; 49 | parentView.layoutFrame = layout; 50 | for (int i = 0; i < 10; i++) { 51 | UIButton *view = (UIButton *)[CUSLayoutSampleFactory createControl:[NSString stringWithFormat:@"%@%i",text,i]]; 52 | view.tag = tag; 53 | [view addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; 54 | [parentView addSubview:view]; 55 | } 56 | } 57 | 58 | -(void)buttonClicked:(UIButton *)button{ 59 | if (button.tag == 0) { 60 | button.tag = 1; 61 | [button removeFromSuperview]; 62 | [bottomView addSubview:button]; 63 | 64 | CGRect frame = button.frame; 65 | frame.origin.y = frame.origin.y - bottomView.frame.origin.y; 66 | button.frame = frame; 67 | }else { 68 | button.tag = 0; 69 | [button removeFromSuperview]; 70 | [topView addSubview:button]; 71 | CGRect frame = button.frame; 72 | frame.origin.y = frame.origin.y + bottomView.frame.origin.y; 73 | button.frame = frame; 74 | } 75 | [topView CUSLayout:YES]; 76 | [bottomView CUSLayout:YES]; 77 | } 78 | @end 79 | 80 | 81 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/typical/CUSSingleViewFillViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CUSSingleViewFillViewController.h 3 | // CUSLayoutExample 4 | // 5 | // Created by zhangyu on 14-6-11. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSTypicalCasesViewController.h" 10 | 11 | @interface CUSSingleViewFillViewController : CUSTypicalCasesViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/typical/CUSSingleViewFillViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSSingleViewFillViewController.m 3 | // CUSLayoutExample 4 | // 5 | // Created by zhangyu on 14-6-11. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSSingleViewFillViewController.h" 10 | 11 | @implementation CUSSingleViewFillViewController 12 | -(void)viewDidLoad{ 13 | [super viewDidLoad]; 14 | self.view.layoutFrame = CUSLAYOUT.share_fillLayout_H; 15 | UIView *view = [CUSLayoutSampleFactory createControl:@"fill"]; 16 | [self.view addSubview:view]; 17 | } 18 | @end -------------------------------------------------------------------------------- /CUSLayoutExample/controller/typical/CUSThreeViewExtendViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CUSThreeViewExtendViewController.h 3 | // CUSLayoutExample 4 | // 5 | // Created by zhangyu on 14-6-11. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSTypicalCasesViewController.h" 10 | 11 | @interface CUSThreeViewExtendViewController : CUSTypicalCasesViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/typical/CUSThreeViewExtendViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSThreeViewExtendViewController.m 3 | // CUSLayoutExample 4 | // 5 | // Created by zhangyu on 14-6-11. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSThreeViewExtendViewController.h" 10 | 11 | @implementation CUSThreeViewExtendViewController 12 | -(void)viewDidLoad{ 13 | [super viewDidLoad]; 14 | 15 | self.view.layoutFrame = CUSLAYOUT.share_linearLayout_V; 16 | UIView *topView = [CUSLayoutSampleFactory createControl:@"top"]; 17 | CUSLinearData *topData = [[CUSLinearData alloc]init]; 18 | topData.height = 44; 19 | topView.layoutData = topData; 20 | [self.view addSubview:topView]; 21 | 22 | UIView *centerView = [CUSLayoutSampleFactory createControl:@"center"]; 23 | CUSLinearData *centerData = [[CUSLinearData alloc]init]; 24 | centerData.fill = YES; 25 | centerView.layoutData = centerData; 26 | [self.view addSubview:centerView]; 27 | 28 | UIView *bottomView = [CUSLayoutSampleFactory createControl:@"bottom"]; 29 | CUSLinearData *bottomData = [[CUSLinearData alloc]init]; 30 | bottomData.height = 44; 31 | bottomView.layoutData = bottomData; 32 | [self.view addSubview:bottomView]; 33 | } 34 | @end 35 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/typical/CUSTowViewDividedViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CUSTowViewDividedViewController.h 3 | // CUSLayoutExample 4 | // 5 | // Created by zhangyu on 14-6-11. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSTypicalCasesViewController.h" 10 | 11 | @interface CUSTowViewDividedViewController : CUSTypicalCasesViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/typical/CUSTowViewDividedViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSTowViewDividedViewController.m 3 | // CUSLayoutExample 4 | // 5 | // Created by zhangyu on 14-6-11. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSTowViewDividedViewController.h" 10 | 11 | @implementation CUSTowViewDividedViewController 12 | -(void)viewDidLoad{ 13 | [super viewDidLoad]; 14 | self.view.layoutFrame = CUSLAYOUT.share_fillLayout_H; 15 | 16 | [self.view addSubview:[CUSLayoutSampleFactory createControl:@"left"]]; 17 | [self.view addSubview:[CUSLayoutSampleFactory createControl:@"right"]]; 18 | } 19 | @end 20 | 21 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/typical/CUSTypicalCasesViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CUSTypicalCasesViewController.h 3 | // CUSLayoutExample 4 | // 5 | // Created by zhangyu on 14-5-29. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "CUSLayoutSampleFactory.h" 12 | 13 | @interface CUSTypicalCasesViewController : CUSViewController 14 | 15 | @end -------------------------------------------------------------------------------- /CUSLayoutExample/controller/typical/CUSTypicalCasesViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSTypicalCasesViewController.m 3 | // CUSLayoutExample 4 | // 5 | // Created by zhangyu on 14-5-29. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSTypicalCasesViewController.h" 10 | 11 | @implementation CUSTypicalCasesViewController 12 | 13 | @end -------------------------------------------------------------------------------- /CUSLayoutExample/controller/typical/CUSWaterfallViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CUSWaterfallViewController.h 3 | // CUSLayoutExample 4 | // 5 | // Created by zhangyu on 14-6-11. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSTypicalCasesViewController.h" 10 | 11 | @interface CUSWaterfallViewController : CUSTypicalCasesViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /CUSLayoutExample/controller/typical/CUSWaterfallViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSWaterfallViewController.m 3 | // CUSLayoutExample 4 | // 5 | // Created by zhangyu on 14-6-11. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import "CUSWaterfallViewController.h" 10 | 11 | 12 | @interface FallEntity : NSObject 13 | @property(nonatomic,assign)NSInteger column; 14 | @property(nonatomic,assign)NSInteger row; 15 | @property(nonatomic,assign)NSInteger columnSpan; 16 | @property(nonatomic,assign)NSInteger rowSpan; 17 | + (FallEntity *)createR:(NSInteger)r C:(NSInteger)c RS:(NSInteger)rs CS:(NSInteger)cs; 18 | @end 19 | 20 | @implementation FallEntity 21 | @synthesize column; 22 | @synthesize row; 23 | @synthesize columnSpan; 24 | @synthesize rowSpan; 25 | 26 | + (FallEntity *)createR:(NSInteger)r C:(NSInteger)c RS:(NSInteger)rs CS:(NSInteger)cs{ 27 | FallEntity *entity = [[FallEntity alloc]init]; 28 | entity.row = r; 29 | entity.column = c; 30 | entity.rowSpan = rs; 31 | entity.columnSpan = cs; 32 | return entity; 33 | } 34 | @end 35 | 36 | @interface CUSWaterfallViewController() 37 | @property(nonatomic,strong)UIScrollView *scrollView; 38 | @property(nonatomic,strong)NSMutableArray *dataArray; 39 | @property(nonatomic,assign)NSInteger pageCounter; 40 | @end 41 | 42 | 43 | @implementation CUSWaterfallViewController 44 | @synthesize scrollView; 45 | @synthesize pageCounter; 46 | @synthesize dataArray; 47 | -(void)viewDidLoad{ 48 | [super viewDidLoad]; 49 | UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc]initWithTitle:@"add" style:UIBarButtonItemStyleBordered target:self action:@selector(buttonItemClicked)]; 50 | self.navigationItem.rightBarButtonItem = buttonItem; 51 | self.view.layoutFrame = CUSLAYOUT.share_fillLayout_V; 52 | scrollView = [[UIScrollView alloc]init]; 53 | scrollView.scrollEnabled = YES; 54 | scrollView.showsVerticalScrollIndicator = YES; 55 | scrollView.delegate = self; 56 | [self.view addSubview:scrollView]; 57 | self.dataArray = [NSMutableArray array]; 58 | [self addMoreControls]; 59 | } 60 | 61 | -(void)buttonItemClicked{ 62 | [self addMoreControls]; 63 | [scrollView CUSLayout:YES]; 64 | } 65 | 66 | -(void)addMoreControls{ 67 | self.pageCounter++; 68 | scrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.pageCounter * 5 * (60 + 5)); 69 | //prepare data 70 | NSInteger startIndex = [self.dataArray count]; 71 | NSInteger rowIndex = (self.pageCounter - 1)*5; 72 | [self.dataArray addObject:[FallEntity createR:rowIndex + 0 C:0 RS:1 CS:1]]; 73 | [self.dataArray addObject:[FallEntity createR:rowIndex + 0 C:1 RS:2 CS:1]]; 74 | [self.dataArray addObject:[FallEntity createR:rowIndex + 0 C:2 RS:1 CS:1]]; 75 | [self.dataArray addObject:[FallEntity createR:rowIndex + 1 C:0 RS:2 CS:1]]; 76 | [self.dataArray addObject:[FallEntity createR:rowIndex + 1 C:2 RS:2 CS:1]]; 77 | [self.dataArray addObject:[FallEntity createR:rowIndex + 2 C:1 RS:2 CS:1]]; 78 | [self.dataArray addObject:[FallEntity createR:rowIndex + 3 C:0 RS:2 CS:1]]; 79 | [self.dataArray addObject:[FallEntity createR:rowIndex + 3 C:2 RS:1 CS:1]]; 80 | [self.dataArray addObject:[FallEntity createR:rowIndex + 4 C:1 RS:1 CS:2]]; 81 | 82 | //init layou data 83 | NSMutableArray *colums = [NSMutableArray array]; 84 | for (int i = 0 ; i < 3; i++) { 85 | [colums addObject:[CUSValue valueWithPercent:0.33]]; 86 | } 87 | NSMutableArray *rows = [NSMutableArray array]; 88 | for (int i = 0 ; i < self.pageCounter * 5; i++) { 89 | [rows addObject:[CUSValue valueWithFloat:60]]; 90 | } 91 | //merge 92 | CUSTableLayout *layout = [[CUSTableLayout alloc]initWithcolumns:colums rows:rows]; 93 | for (int i = 0; i < [self.dataArray count]; i++) { 94 | FallEntity *entity = [self.dataArray objectAtIndex:i]; 95 | [layout merge:entity.column row:entity.row colspan:entity.columnSpan rowspan:entity.rowSpan]; 96 | } 97 | 98 | //create views 99 | for (int i = (int)startIndex; i < [self.dataArray count]; i++) { 100 | UIView *subView = [CUSLayoutSampleFactory createControl:[NSString stringWithFormat:@"button %i",i]]; 101 | //animate start frame 102 | subView.frame = CGRectMake(160, 0, 0, 0); 103 | [scrollView addSubview:subView]; 104 | } 105 | 106 | scrollView.layoutFrame = layout; 107 | } 108 | -(void)viewDidLayoutSubviews{ 109 | [super viewDidLayoutSubviews]; 110 | 111 | scrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.pageCounter * 5 * (60 + 5)); 112 | } 113 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView_{ 114 | 115 | } 116 | @end 117 | 118 | -------------------------------------------------------------------------------- /CUSLayoutExample/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /CUSLayoutExample/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // CUSLayoutExample 4 | // 5 | // Created by zhangyu on 14-5-21. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CUSAppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([CUSAppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /CUSLayoutExampleTests/CUSLayoutExampleTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.zhangyu.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /CUSLayoutExampleTests/CUSLayoutExampleTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSLayoutExampleTests.m 3 | // CUSLayoutExampleTests 4 | // 5 | // Created by zhangyu on 14-5-21. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CUSLayoutExampleTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation CUSLayoutExampleTests 16 | 17 | - (void)setUp 18 | { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown 24 | { 25 | // Put teardown code here. This method is called after the invocation of each test method in the class. 26 | [super tearDown]; 27 | } 28 | 29 | - (void)testExample 30 | { 31 | XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /CUSLayoutExampleTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /CUSLayoutTests/CUSLayoutTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.zhangyu.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /CUSLayoutTests/CUSLayoutTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // CUSLayoutTests.m 3 | // CUSLayoutTests 4 | // 5 | // Created by zhangyu on 14-5-21. 6 | // Copyright (c) 2014年 zhangyu. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CUSLayoutTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation CUSLayoutTests 16 | 17 | - (void)setUp 18 | { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown 24 | { 25 | // Put teardown code here. This method is called after the invocation of each test method in the class. 26 | [super tearDown]; 27 | } 28 | 29 | - (void)testExample 30 | { 31 | XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /CUSLayoutTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2013 ZHANGYU Inc - http://weibo.com/cuslayout 2 | 3 | -------- 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 6 | file except in compliance with the License. You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software distributed under 11 | the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 12 | ANY KIND, either express or implied. See the License for the specific language governing 13 | permissions and limitations under the License. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CUSLayout 2 | ========= 3 | CUSLayout for iOS managed positioning mechanism, the iOS SDK provides absolute positioning is very inconvenient to use, in addition to the emergence of 4-inch screen of the iPhone and iPad to make iOS developer need to spend more time in the layout, however iOS6.0 AutoLayout the mechanism is disappointing, I refer to Android, SWT, Swing layout mechanism, the preparation of for iOS CUSLayout, use CUSLayout has the following advantages:
- Simplify coding, you do not need to take into account the pixel level, only for regional programming, which greatly improves the efficiency of programming
- Good readability, layout type can be a preliminary understanding of layout intent and child controls roughly placed, eliminating the need for a very tedious restore coordinate steps
- When the the UIView container Flip, size change, supporting multiple resolutions, automatic processing
- UIView category which makes it easy to create layout constraints in old code
- The API is simple and easy-to-use, low cost learning through the sample program to preliminary master
4 | 5 | ------------------------------------ 6 | How To Get Started 7 | ==================================== 8 | ###Use static library 9 | - 1.Open your existing project (or create a new one) 10 | - 2.Drag and drop the CUSLayoutExample.xcodeproj file downloaded from github previously from Finder to your project (either root or under Frameworks) 11 | 12 | - 3.In YOUR project configuration:
13 | in the Build Phases, Add CUSLayout (the lib, not the example app) as a Target Dependency
14 | in the Link Binary With Libraries section, add the libCUSLayout.a library
15 | - 4.In YOUR Prefix.pch file, add: 16 | 17 | \#import “CUSLayout.h” 18 | 19 | - 5.In YOUR project configuration, on the “Build Settings” tab 20 | 21 | - locate the “User Header Search Paths” setting, and set the Release value to "${PROJECT_DIR}/CUSLayout" (including quotes!) and check the “Recursive” check box. 22 | - The Debug value should already be set, but if it’s not, change that as well. 23 | - Also locate the “Always Search User Paths” value and set it to YES. 24 | - Finally, find the “Other Linker Flags” option, and add the value -ObjC (no quotes). 25 | 26 | ### Installation with CocoaPods 27 | 28 | [CocoaPods](http://cocoapods.org) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like CUSLayout in your projects. See the ["Getting Started" guide for more information](https://github.com/JJMM/CUSLayout/wiki/Getting-Started-with-CUSLayout). 29 | 30 | #### Podfile 31 | 32 | ```ruby 33 | platform:ios 34 | pod "CUSLayout" 35 | ``` 36 | ------------------------------------ 37 | API 38 | ==================================== 39 | ###Base Layout 40 | CUSFillLayout
41 | CUSStackLayout
42 | CUSLinnerLayout
43 | ###Advanced Layout 44 | CUSRowLayout
45 | CUSTableLayout
46 | CUSGridLayout
47 | 48 | ------------------------------------ 49 | Basic usage 50 | ==================================== 51 | ###CUSFillLayout 52 | ```objective-c 53 | //only one code,auto set the frame of parent to the subview. 54 | view.layoutFrame = [[CUSFillLayout alloc]init]; 55 | 56 | ``` 57 | 58 | ------------------------------------ 59 | Example 60 | ==================================== 61 | ![image](https://github.com/JJMM/CUSResources/raw/master/CUSLayout/FillLayout.jpg)
62 | ![image](https://github.com/JJMM/CUSResources/raw/master/CUSLayout/StackLayout.jpg)
63 | ![image](https://github.com/JJMM/CUSResources/raw/master/CUSLayout/LinnerLayout.jpg)
64 | ![image](https://github.com/JJMM/CUSResources/raw/master/CUSLayout/RowLayout.jpg)
65 | ![image](https://github.com/JJMM/CUSResources/raw/master/CUSLayout/TableLayout.jpg)
66 | ![image](https://github.com/JJMM/CUSResources/raw/master/CUSLayout/GridLayout.jpg)
67 | ![image](https://github.com/JJMM/CUSResources/raw/master/CUSLayout/LayoutManager.jpg) 68 | 69 | ## License 70 | CUSLayout is licensed under the terms of the [Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html). Please see the [LICENSE](LICENSE) file for full details. 71 | 72 | ## Contributions 73 | 74 | Contributions are totally welcome. We'll review all pull requests and if you send us a good one/are interested we're happy to give you push access to the repo. Or, you know, you could just come work with us.
75 | 76 | Please pay attention to add Star, your support is my greatest motivation, thank you. --------------------------------------------------------------------------------