Skip to content

Commit ef03588

Browse files
author
欧柏泉
committed
Release v1.5.0
1 parent 182d68f commit ef03588

File tree

1 file changed

+14
-45
lines changed

1 file changed

+14
-45
lines changed

MyLayoutDemo/GLTest4ViewController.m

+14-45
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ - (void)viewDidLoad {
7474
[super viewDidLoad];
7575
// Do any additional setup after loading the view.
7676

77-
[self test1];
77+
[self createLayout];
7878

7979
[self bindView];
8080
}
@@ -175,18 +175,24 @@ - (void)viewDidLoad {
175175

176176

177177

178-
- (void)test1
178+
- (void)createLayout
179179
{
180+
/*
181+
这个例子演示一个通过JSON格式描述的栅格来构建栅格布局的示例。
182+
*/
180183
self.edgesForExtendedLayout = UIRectEdgeNone;
181184
MyGridLayout *rootLayout = [MyGridLayout new];
182185
rootLayout.backgroundColor = [UIColor whiteColor];
183-
rootLayout.gridActionTarget = self;
184-
self.view = rootLayout;
186+
rootLayout.myMargin = MyLayoutPos.safeAreaMargin;
187+
[self.view addSubview:rootLayout];
185188
self.rootLayout = rootLayout;
186-
NSString *path = [NSBundle.mainBundle pathForResource:@"GridLayoutDemo4.json" ofType:nil];
187-
NSString *content = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
188-
id temp = [NSJSONSerialization JSONObjectWithData:[content dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:nil];
189-
rootLayout.gridDictionary = temp;
189+
190+
191+
rootLayout.gridActionTarget = self; //因为JSON格式的栅格描述是无法指定事件的执行者的,因此栅格布局提供了这个属性来设置所有通过字典或者通过JSON来构建栅格布局时的事件执行者。
192+
193+
//从JSON格式的文件中来构建栅格布局.
194+
NSString *jsonFilePath = [NSBundle.mainBundle pathForResource:@"GridLayoutDemo4.json" ofType:nil];
195+
rootLayout.gridDictionary = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:jsonFilePath] options:NSJSONReadingAllowFragments error:nil];
190196
}
191197

192198

@@ -307,43 +313,6 @@ -(void)bindView
307313
}
308314
[self.rootLayout addViewGroup:temp withActionData:model.actionDatas to:sPartTag4];
309315
}
310-
311-
// NSArray *titles = @[@"海抢购",@"有好货",@"必买清单"];
312-
// NSArray *subTitles = @[@"01:29:45",@"高颜值美物",@"都整理好"];
313-
// NSArray *imageNames = @[@[@"p1-33",@"p1-34"],@[@"p1-33",@"p1-34"],@[@"p1-33",@"p1-34"]];
314-
// NSArray *actionDatas = @[@"bb",@"cc",@"dd"];
315-
// NSArray *hasSales = @[@(NO),@(NO),@(YES)];
316-
// for(int i = 0 ; i < titles.count; i++) {
317-
// NSString *title = [titles objectAtIndex:i];
318-
// NSString *subTitle = [subTitles objectAtIndex:i];
319-
// NSArray *tempImages = [imageNames objectAtIndex:i];
320-
// NSString *actionData = [actionDatas objectAtIndex:i];
321-
// NSString *hasSale = [hasSales objectAtIndex:i];
322-
//
323-
// NSMutableArray *temp = [NSMutableArray array];
324-
// UILabel *titleLabel = [UILabel new];
325-
// titleLabel.text = title;
326-
// titleLabel.font = [CFTool font:16];
327-
// titleLabel.textColor = [CFTool color:4];
328-
// titleLabel.adjustsFontSizeToFitWidth = YES;
329-
// [temp addObject:titleLabel];
330-
//
331-
// UILabel *subTitleLabel = [UILabel new];
332-
// subTitleLabel.text = subTitle;
333-
// subTitleLabel.font = [CFTool font:13];
334-
// subTitleLabel.textColor = [CFTool color:5];
335-
// subTitleLabel.adjustsFontSizeToFitWidth = YES;
336-
// [temp addObject:subTitleLabel];
337-
// for (NSString *imageName in tempImages) {
338-
// UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
339-
// [temp addObject:imageView];
340-
// }
341-
// if ([hasSale boolValue]) {
342-
// UIImageView *optionalView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"p1-12"]];
343-
// [temp addObject:optionalView];
344-
// }
345-
// [self.rootLayout addViewGroup:temp withActionData:actionData to:sPartTag4];
346-
// }
347316
}
348317
}
349318

0 commit comments

Comments
 (0)