@@ -74,7 +74,7 @@ - (void)viewDidLoad {
74
74
[super viewDidLoad ];
75
75
// Do any additional setup after loading the view.
76
76
77
- [self test1 ];
77
+ [self createLayout ];
78
78
79
79
[self bindView ];
80
80
}
@@ -175,18 +175,24 @@ - (void)viewDidLoad {
175
175
176
176
177
177
178
- - (void )test1
178
+ - (void )createLayout
179
179
{
180
+ /*
181
+ 这个例子演示一个通过JSON格式描述的栅格来构建栅格布局的示例。
182
+ */
180
183
self.edgesForExtendedLayout = UIRectEdgeNone;
181
184
MyGridLayout *rootLayout = [MyGridLayout new ];
182
185
rootLayout.backgroundColor = [UIColor whiteColor ];
183
- rootLayout.gridActionTarget = self ;
184
- self.view = rootLayout;
186
+ rootLayout.myMargin = MyLayoutPos. safeAreaMargin ;
187
+ [ self .view addSubview: rootLayout] ;
185
188
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 ];
190
196
}
191
197
192
198
@@ -307,43 +313,6 @@ -(void)bindView
307
313
}
308
314
[self .rootLayout addViewGroup: temp withActionData: model.actionDatas to: sPartTag4 ];
309
315
}
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
- // }
347
316
}
348
317
}
349
318
0 commit comments