KLCPopup 라이브러리를 사용하여 내 앱에 팝업을 표시합니다. 표준 iOS UIAlerView처럼이 팝업의 하단에 수평으로 2 개의 버튼을 추가해야합니다. 이 두 버튼을 수평으로 정렬 할 수 없습니다. 내가 가진레이아웃에서 프로그래밍 방식으로 2 개의 uvutton을 정렬하는 방법은 무엇입니까?
그러나 여기 결과입니다 :
UIView* contentView = [[UIView alloc] init];
contentView.translatesAutoresizingMaskIntoConstraints = NO;
UILabel* dismissLabel = [[UILabel alloc] init];
dismissLabel.translatesAutoresizingMaskIntoConstraints = NO;
dismissLabel.numberOfLines = 0;
[dismissLabel setTextAlignment:NSTextAlignmentCenter];
dismissLabel.lineBreakMode = NSLineBreakByWordWrapping;
dismissLabel.preferredMaxLayoutWidth = 200;
UIButton* dismissButton = [UIButton buttonWithType:UIButtonTypeCustom];
dismissButton.translatesAutoresizingMaskIntoConstraints = NO;
dismissButton.contentEdgeInsets = UIEdgeInsetsMake(10, 20, 10, 20);
[contentView addSubview:dismissLabel];
[contentView addSubview:dismissButton];
UIButton* cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
cancelButton.translatesAutoresizingMaskIntoConstraints = NO;
cancelButton.contentEdgeInsets = UIEdgeInsetsMake(10, 20, 10, 20);
[contentView addSubview:cancelButton];
NSDictionary* views = NSDictionaryOfVariableBindings(contentView, dismissButton, cancelButton, dismissLabel);
[contentView addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(16)-[dismissLabel]-(16)-[dismissButton]-(16)-[cancelButton]-(16)-|"
options:NSLayoutFormatAlignAllCenterX
metrics:nil
views:views]];
[contentView addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(18)-[dismissLabel]-(18)-|"
options:0
metrics:nil
views:views]];
// Show in popup
KLCPopupLayout layout = KLCPopupLayoutMake(KLCPopupHorizontalLayoutCenter,
KLCPopupVerticalLayoutCenter);
KLCPopup* popup = [KLCPopup popupWithContentView:contentView
showType:KLCPopupShowTypeFadeIn
dismissType:KLCPopupDismissTypeGrowOut
maskType:KLCPopupMaskTypeDimmed
dismissOnBackgroundTouch:NO
dismissOnContentTouch:NO];
[popup showWithLayout:layout];
: 여기
내가이 팝업을 만드는 데 사용하는 코드는 여기에 내가을 원하는 결과입니다
내 코드의 문제는 제약이라고 생각합니다. 많은 가능성을 시도했지만 올바른 방법을 찾을 수 없습니다.
조언이 도움이 될 것입니다.
덕분에
이 문제를 발견 한 행운? 나는 똑같은 라이브러리에 똑같은 것을 직면하고있다. =/@barrast –
마지막으로 필자는 TTAlertView (https://github.com/twotoasters/TTAlertView)를 사용하여 내 필요에 더 유용했습니다. – barrast