Open
Description
子视图为自定义样式,使用Masonry布局,无法展示;demo代码如下:
UIView *view = [[UIView alloc] init];
view.backgroundColor = [UIColor grayColor];
UIImageView *imageView = [[UIImageView alloc] init];
imageView.backgroundColor = [UIColor redColor];
imageView.clipsToBounds = YES;
imageView.layer.cornerRadius = 8;
[view addSubview:imageView];
[imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(view).offset(5);
make.top.greaterThanOrEqualTo(view).offset(2);
make.centerY.equalTo(view);
make.width.height.equalTo(@16);
}];
UILabel *label = [[UILabel alloc] init];
label.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.5];
label.text = [NSString stringWithFormat:@" label%d ", i];
label.clipsToBounds = YES;
label.layer.cornerRadius = 8;
label.layer.borderColor = [UIColor lightGrayColor].CGColor;
label.layer.borderWidth = 0.5;
[view addSubview:label];
[label mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(imageView.mas_right).offset(5);
make.right.lessThanOrEqualTo(view).offset(-5);
make.top.greaterThanOrEqualTo(view).offset(8);
make.centerY.equalTo(view);
make.height.greaterThanOrEqualTo(@16);
}];
[self.flowLayout addSubview:view];
-(MyFlowLayout *)flowLayout {
if(_flowLayout == nil) {
_flowLayout = [MyFlowLayout flowLayoutWithOrientation:MyOrientation_Vert arrangedCount:0];
_flowLayout.subviewHSpace = 16; // 子视图之间的水平间距
_flowLayout.subviewVSpace = 8; // 子视图之间的垂直间距
_flowLayout.padding = UIEdgeInsetsMake(5, 5, 5, 5); // 视图四周的内边距值
}
return _flowLayout;
}
Metadata
Metadata
Assignees
Labels
No labels