昨天难得串休,还是闲不住写了个项目中能用到的小demo,废话不说,就是上
实际效果:
实现很简单,根据位置设约束优先级
UIButton *jing2 = [UIButton buttonWithType:UIButtonTypeCustom];
[jing2 setTitle:@"静" forState:UIControlStateNormal];
[jing2 setBackgroundColor:[UIColor magentaColor]];
[jing2 addTarget:self action:@selector(buttonDidClick:) forControlEvents:UIControlEventTouchUpInside];
[self.myView addSubview:jing2];
[jing2 makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(_myView);
make.left.equalTo(_myView).priority(450);// 越靠近左边,优先级越高
make.right.equalTo(jing.left).offset(-4);//中间其他的,优先级逐级递减
make.right.equalTo(rong.left).offset(-4).priority(450);//中间其他的,优先级逐级递减
make.right.equalTo(tong.left).offset(-4).priority(400);//中间其他的,优先级逐级递减,注意,优先级要大于 label 的优先级
make.right.equalTo(label.left).offset(-4).priority(350);// 越靠近左边,优先级越低
}];
这里只放最左面的button约束