如何使用masonry设计复合型cell
1个回答
展开全部
方法:
布局代码如下:
@interface ComplexCell()
@property (nonatomic, strong) UIView *vB; //view blue height:30
@property (nonatomic, strong) UIView *vY; //view yellow height:30
@property (nonatomic, strong) UIView *vR; //view red height:30
@property (nonatomic, strong) UIView *vG; //view green height:100
@end
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if ( self ) {
CGFloat spacing = 20.0f;
self.vB = [UIView new];
[self.contentView addSubview:self.vB];
[self.vB mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.equalTo(self.contentView).insets(UIEdgeInsetsMake(spacing,spacing,0,0));
make.width.equalTo(@60);
make.height.equalTo(@30).priorityLow();
self.cB = make.height.equalTo(@0).priority(UILayoutPriorityRequired);
}];
self.vB.backgroundColor = [UIColor blueColor];
self.vY = [UIView new];
[self.contentView addSubview:self.vY];
[self.vY mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.vB.mas_right).offset(spacing);
make.right.top.equalTo(self.contentView).insets(UIEdgeInsetsMake(spacing,0,0,spacing));
make.height.equalTo(@30).priorityLow();
self.cY = make.height.equalTo(@0).priority(UILayoutPriorityRequired);
}];
self.vY.backgroundColor = [UIColor yellowColor];
self.vR = [UIView new];
[self.contentView addSubview:self.vR];
[self.vR mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.vB.mas_bottom).offset(spacing);
make.left.right.equalTo(self.contentView).insets(UIEdgeInsetsMake(0,spacing,0,spacing));
make.height.equalTo(@30).priorityLow();
self.cR = make.height.equalTo(@0).priority(UILayoutPriorityRequired);
}];
self.vR.backgroundColor = [UIColor redColor];
self.vG = [UIView new];
[self.contentView addSubview:self.vG];
[self.vG mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.vR.mas_bottom).offset(spacing);
make.left.right.equalTo(self.contentView).insets(UIEdgeInsetsMake(0,spacing,0,spacing));
make.height.equalTo(@100).priorityLow();
self.cG = make.height.equalTo(@0).priority(UILayoutPriorityRequired);
}];
self.vG.backgroundColor = [UIColor greenColor];
}
return self;
}
布局代码如下:
@interface ComplexCell()
@property (nonatomic, strong) UIView *vB; //view blue height:30
@property (nonatomic, strong) UIView *vY; //view yellow height:30
@property (nonatomic, strong) UIView *vR; //view red height:30
@property (nonatomic, strong) UIView *vG; //view green height:100
@end
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if ( self ) {
CGFloat spacing = 20.0f;
self.vB = [UIView new];
[self.contentView addSubview:self.vB];
[self.vB mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.equalTo(self.contentView).insets(UIEdgeInsetsMake(spacing,spacing,0,0));
make.width.equalTo(@60);
make.height.equalTo(@30).priorityLow();
self.cB = make.height.equalTo(@0).priority(UILayoutPriorityRequired);
}];
self.vB.backgroundColor = [UIColor blueColor];
self.vY = [UIView new];
[self.contentView addSubview:self.vY];
[self.vY mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.vB.mas_right).offset(spacing);
make.right.top.equalTo(self.contentView).insets(UIEdgeInsetsMake(spacing,0,0,spacing));
make.height.equalTo(@30).priorityLow();
self.cY = make.height.equalTo(@0).priority(UILayoutPriorityRequired);
}];
self.vY.backgroundColor = [UIColor yellowColor];
self.vR = [UIView new];
[self.contentView addSubview:self.vR];
[self.vR mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.vB.mas_bottom).offset(spacing);
make.left.right.equalTo(self.contentView).insets(UIEdgeInsetsMake(0,spacing,0,spacing));
make.height.equalTo(@30).priorityLow();
self.cR = make.height.equalTo(@0).priority(UILayoutPriorityRequired);
}];
self.vR.backgroundColor = [UIColor redColor];
self.vG = [UIView new];
[self.contentView addSubview:self.vG];
[self.vG mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.vR.mas_bottom).offset(spacing);
make.left.right.equalTo(self.contentView).insets(UIEdgeInsetsMake(0,spacing,0,spacing));
make.height.equalTo(@100).priorityLow();
self.cG = make.height.equalTo(@0).priority(UILayoutPriorityRequired);
}];
self.vG.backgroundColor = [UIColor greenColor];
}
return self;
}
光点科技
2023-08-15 广告
2023-08-15 广告
通常情况下,我们会按照结构模型把系统产生的数据分为三种类型:结构化数据、半结构化数据和非结构化数据。结构化数据,即行数据,是存储在数据库里,可以用二维表结构来逻辑表达实现的数据。最常见的就是数字数据和文本数据,它们可以某种标准格式存在于文件...
点击进入详情页
本回答由光点科技提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询