如何在autocorrect(colour1)
下添加文字视图?我尝试过以下方法,但textview显示不正确。
UIAlertController
答案 0 :(得分:5)
查看此代码。测试
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Some title"
message:@"\n\n\n\n\n\n\n\n"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* okay = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//Do Some action here
}];
UIAlertAction* cancel1 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
[alertController dismissViewControllerAnimated:YES completion:nil];
}];
[alertController addAction:okay];
[alertController addAction:cancel1];
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:^{
}];
答案 1 :(得分:0)
检查此代码。它对我来说很好。
self.alertController = [UIAlertController alertControllerWithTitle:@"Some title"
message:@"Last year, in addition to the major redesign, we also got Maps apps, so everything from ride-sharing to reservation making could live in and enhance maps. We also got steady progress for Apple Maps on the web.expect we'll see some of the next-generation of Maps updates at WWDC 2017 but here's hoping Apple can shed its dependence on TomTom data, accelerate the updates, and start closing that gap."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[self.alertController dismissViewControllerAnimated:YES completion:nil];
}];
self.alertController.view.autoresizesSubviews = YES;
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectZero];
textView.translatesAutoresizingMaskIntoConstraints = NO;
textView.editable = NO;
textView.dataDetectorTypes = UIDataDetectorTypeAll;
textView.userInteractionEnabled = YES;
textView.backgroundColor = [UIColor clearColor];
textView.scrollEnabled = YES;
[self.alertController addAction:ok];
[self presentViewController:self.alertController animated:YES completion:nil];