Skip to content

Commit 5bf6ec8

Browse files
sunyong0329sunyong0329
authored andcommitted
add constrant
1 parent c97701f commit 5bf6ec8

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

TYAlertControllerDemo/TYAlertController/TYAlertView.m

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,24 @@ - (void)layoutButtons
225225
[_buttonContentView addConstarintWithView:button topView:_buttonContentView leftView:nil bottomView:nil rightView:_buttonContentView edageInset:UIEdgeInsetsZero];
226226
[_buttonContentView addConstarintWithLeftView:firstButton toRightView:button constarint:_textLabelSpace];
227227
[_buttonContentView addConstarintEqualWithView:button widthToView:firstButton heightToView:firstButton];
228-
}}
228+
}else {
229+
if (_buttons.count == 3) {
230+
UIButton *firstBtn = _buttons[0];
231+
UIButton *secondBtn = _buttons[1];
232+
[_buttonContentView removeConstraintWithView:firstBtn attribte:NSLayoutAttributeRight];
233+
[_buttonContentView removeConstraintWithView:firstBtn attribte:NSLayoutAttributeBottom];
234+
[_buttonContentView removeConstraintWithView:secondBtn attribte:NSLayoutAttributeTop];
235+
[_buttonContentView addConstarintWithView:firstBtn topView:nil leftView:nil bottomView:0 rightView:_buttonContentView edageInset:UIEdgeInsetsZero];
236+
[_buttonContentView addConstarintWithTopView:firstBtn toBottomView:secondBtn constarint:_textLabelSpace];
237+
238+
}
239+
UIButton *lastSecondBtn = _buttons[_buttons.count-2];
240+
[_buttonContentView removeConstraintWithView:lastSecondBtn attribte:NSLayoutAttributeBottom];
241+
[_buttonContentView addConstarintWithTopView:lastSecondBtn toBottomView:button constarint:_textLabelSpace];
242+
[_buttonContentView addConstarintWithView:button topView:nil leftView:_buttonContentView bottomView:_buttonContentView rightView:nil edageInset:UIEdgeInsetsZero];
243+
[_buttonContentView addConstarintEqualWithView:button widthToView:lastSecondBtn heightToView:lastSecondBtn];
244+
}
245+
}
229246

230247
#pragma mark - action
231248

TYAlertControllerDemo/TYAlertController/UIView+TYAutoLayout.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ - (void)addConstarintWithLeftView:(UIView *)leftView toRightView:(UIView *)right
4242

4343
- (void)addConstarintWithTopView:(UIView *)topView toBottomView:(UIView *)bottomView constarint:(CGFloat)constarint
4444
{
45-
[self addConstraint:[NSLayoutConstraint constraintWithItem:bottomView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:topView attribute:NSLayoutAttributeBottom multiplier:1 constant:constarint]];
45+
[self addConstraint:[NSLayoutConstraint constraintWithItem:topView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:bottomView attribute:NSLayoutAttributeTop multiplier:1 constant:-constarint]];
4646
}
4747

4848
- (void)addConstarintWidth:(CGFloat)width height:(CGFloat)height

TYAlertControllerDemo/ViewController.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ - (IBAction)showAlertView:(id)sender {
3434
}]];
3535
[alertView addAction:[TYAlertAction actionWithTitle:@"取消" style:TYAlertActionStyleCancle handler:^(TYAlertAction *action) {
3636

37+
}]];
38+
[alertView addAction:[TYAlertAction actionWithTitle:@"默认" style:TYAlertActionStyleDefault handler:^(TYAlertAction *action) {
39+
3740
}]];
3841
TYAlertController *alertController = [TYAlertController alertControllerWithAlertView:alertView preferredStyle:TYAlertControllerStyleAlert];
3942
[self presentViewController:alertController animated:YES completion:nil];

0 commit comments

Comments
 (0)