用户必须为他们的个人资料编写摘要,因此他们需要一个很大的空间来写入.整个应用程序是使用AlertControllerd出窗口构建的,所以我想用更大的多行UITextFIEld替换单行UITextFIEld.
我能做些什么来实现这一目标?
我目前添加了以下代码:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:@"Enter your summary" preferredStyle:UIAlertControllerStyleAlert]; [alert addTextFIElDWithConfigurationHandler:^(UITextFIEld * _Nonnull textFIEld) { textFIEld.placeholder = @"Summary"; textFIEld.autocAPItalizationType = UITextautocAPItalizationTypeSentences; textFIEld.text = _summaryLabel.text; NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:textFIEld attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplIEr:1 constant: 110.0]; [textFIEld addConstraint:constraint]; [textFIEld layoutIfNeeded]; }];
这意味着UITextFIEld实际上更大,但它不是多线,它也是垂直居中的文本.我该怎么办?
解决方法 正如@rmaddy所说,UITextFIEld仅适用于单行,可以使用UITextVIEw.你可以通过这个完成:
How to use UITextView in UIAlertController
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Enter your summary" message:@"\n\n\n\n\n\n\n\n" preferredStyle:UIAlertControllerStyleAlert];alert.vIEw.autoresizesSubvIEws = YES;UITextVIEw *textVIEw = [[UITextVIEw alloc] initWithFrame:CGRectZero];textVIEw.translatesautoresizingMaskIntoConstraints = NO;NSLayoutConstraint *leadConstraint = [NSLayoutConstraint constraintWithItem:alert.vIEw attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:textVIEw attribute:NSLayoutAttributeLeading multiplIEr:1.0 constant:-8.0];NSLayoutConstraint *trailConstraint = [NSLayoutConstraint constraintWithItem:alert.vIEw attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:textVIEw attribute:NSLayoutAttributeTrailing multiplIEr:1.0 constant:8.0];NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:alert.vIEw attribute:NSLayoutAttributetop relatedBy:NSLayoutRelationEqual toItem:textVIEw attribute:NSLayoutAttributetop multiplIEr:1.0 constant:-64.0];NSLayoutConstraint *bottomConstraint = [NSLayoutConstraint constraintWithItem:alert.vIEw attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:textVIEw attribute:NSLayoutAttributeBottom multiplIEr:1.0 constant:64.0];[alert.vIEw addSubvIEw:textVIEw];[NSLayoutConstraint activateConstraints:@[leadConstraint,trailConstraint,topConstraint,bottomConstraint]];[alert addAction: [UIAlertAction actionWithTitle:@"Done"style:UIAlertActionStyleDefault handler:^(UIAlertAction*action) { NSLog(@"%@",textVIEw.text);}]];[self presentVIEwController:alert animated:YES completion:nil];
或者使用UIAlertVIEw:
How to Insert the UITextView into UIAlertview in iOS
UIAlertVIEw *alert = [[UIAlertVIEw alloc] initWithTitle:@"" message:@"Enter your summary" delegate:self cancelbuttonTitle:@"Cancel" otherbuttonTitles:@"Done",nil];UITextVIEw *textVIEw = [[UITextVIEw alloc] initWithFrame:CGRectZero];[alert setValue:textVIEw forKey:@"accessoryVIEw"];[alert show];
或者像ios-custom-alertview一样定制自己的警报
总结以上是内存溢出为你收集整理的带有多行UITextField的iOS AlertController全部内容,希望文章能够帮你解决带有多行UITextField的iOS AlertController所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)