0

Does Apple review allows the below coding i.e adding a textView or label as a "accessoryView" .. I read in many places that its not a public exposed api and we should not do this way.. but few says we can... will it get rejected while we send for review. Please guide me...

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"];
DGoogly
  • 329
  • 2
  • 16
  • Are you working on latest iOS version? If Yes, then please use AlertController for displaying alert. Here are few links which can be helpful http://stackoverflow.com/questions/31922349/how-to-add-textfield-to-uialertcontroller-in-swift http://stackoverflow.com/questions/37696485/show-the-textfield-in-the-alertcontroller-in-swift – Gagan_iOS May 09 '17 at 04:50
  • Thanks for the help. Yes Im using latest version of iOS. But I wanted to add a textview not a textfield. – DGoogly May 09 '17 at 04:56
  • ok..I suggest go for multiline textfield as in this link http://stackoverflow.com/questions/34420080/multiline-editable-text-uitextview-inside-uialertcontroller also look at this link http://stackoverflow.com/questions/28603060/how-to-use-uitextview-in-uialertcontroller – Gagan_iOS May 09 '17 at 04:58
  • i could see that they have used "addSubView" to an UIAlertController to add the textview.. Is that a proper way? – DGoogly May 09 '17 at 05:09
  • did you the desired result? If yes, then there is no harm to add a view on any controller's view. UIAlertcontroller is also controller not like AlertView. – Gagan_iOS May 09 '17 at 05:12

1 Answers1

0

For Add text view on Alert use this code

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:^{

}];
Jignesh Mayani
  • 6,937
  • 1
  • 20
  • 36