Skip to content

Instantly share code, notes, and snippets.

@hanfengs
Created August 20, 2019 09:23
Show Gist options
  • Save hanfengs/df1e53ebdbbd63acfe630ccb00ac25dd to your computer and use it in GitHub Desktop.
Save hanfengs/df1e53ebdbbd63acfe630ccb00ac25dd to your computer and use it in GitHub Desktop.
[多选项(4或者更多),自动布局]
UIImageView *lastIV = nil;
self.ivArrM = [NSMutableArray array];
for (NSInteger i = 0; i < 4; i++) {
UIImageView *iv = [[UIImageView alloc] init];
[self addSubview:iv];
[iv mas_makeConstraints:^(MASConstraintMaker *make) {
if (isPad) {
make.width.mas_equalTo(163);
}else{
make.width.equalTo(self).multipliedBy(0.5).offset(-IVMragin16 * 1.5);
}
make.height.equalTo(iv.mas_width).multipliedBy(0.6);
if (lastIV) {
if (i%2 == 0) {
make.left.equalTo(self).offset(IVMragin16);
make.top.equalTo(lastIV.mas_bottom).offset(IVMragin16);
}else{
make.left.equalTo(lastIV.mas_right).offset(IVMragin16);
make.top.equalTo(lastIV);
}
}else{
make.left.equalTo(self).offset(IVMragin16);
make.top.equalTo(index.mas_bottom).offset(20);
}
}];
lastIV = iv;
[self.ivArrM addObject:iv];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment