簡體   English   中英

將UITextView或UILabel作為“ accessoryView”添加到UIAlertView?

[英]Adding a UITextView or UILabel to UIAlertView as “accessoryView”?

蘋果審查是否允許以下​​編碼,即添加textView或標簽作為“ accessoryView” ..我在很多地方都讀到它不是公開的api,所以我們不應該這樣做。.但是很少有人說我們可以...在我們發送審查時被拒絕。 請指導我...

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 100, 200)];
textView.selectable = YES;
textView.editable = NO;
textView.attributedText = attributedStr;
UIAlertView *customAlert = [[UIAlertView alloc] initWithTitle:@"Title" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
[customAlert setValue:textView forKey:@"accessoryView"];

對於在Alert上添加文本視圖,請使用此代碼

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Some title"
                                                                         message:@"\n\n\n\n\n\n\n\n"
                                                                  preferredStyle:UIAlertControllerStyleAlert];
alertController.view.autoresizesSubviews = YES;
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectZero];
textView.translatesAutoresizingMaskIntoConstraints = NO;
textView.editable = YES;
textView.dataDetectorTypes = UIDataDetectorTypeAll;
textView.text = @"Some really long text here";
textView.userInteractionEnabled = YES;
textView.backgroundColor = [UIColor whiteColor];
textView.scrollEnabled = YES;
NSLayoutConstraint *leadConstraint = [NSLayoutConstraint constraintWithItem:alertController.view attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:textView attribute:NSLayoutAttributeLeading multiplier:1.0 constant:-8.0];
NSLayoutConstraint *trailConstraint = [NSLayoutConstraint constraintWithItem:alertController.view attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:textView attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:8.0];

NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:alertController.view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:textView attribute:NSLayoutAttributeTop multiplier:1.0 constant:-64.0];
NSLayoutConstraint *bottomConstraint = [NSLayoutConstraint constraintWithItem:alertController.view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:textView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:64.0];
[alertController.view addSubview:textView];
[NSLayoutConstraint activateConstraints:@[leadConstraint, trailConstraint, topConstraint, bottomConstraint]];

[self presentViewController:alertController animated:YES completion:^{

}];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM