gpt4 book ai didi

ios - 是否可以在 UIAlertController 的一行中插入两个文本字段

转载 作者:行者123 更新时间:2023-11-28 05:32:54 26 4
gpt4 key购买 nike

我试图将两个文本字段放在 UIAlertController(以前称为 UIAlertView)内的一行中,以便创建电话号码输入 - 一个用于国家代码,一个用于号码(我需要将它们分开)。是否有可能做到这一点? swift 回答将不胜感激。 :)

That is what I want to achieve

最佳答案

这是我的一段 Swift 代码。这个对我有用。我希望它也适用于其他人。

class NumbersViewController: UIViewController, UITextFieldDelegate {

var codeTextField: UITextField?;
var numberTextField: UITextField?;

override func viewDidLoad() {
super.viewDidLoad();
}

override func viewDidAppear(animated: Bool) {
self.askForNumber();
}



func askForNumber(prefix: String = ""){
var title = "";
var message = "Enter your mobile number\n\n\n";
var alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert);
alert.modalInPopover = true;

func handleOk(alertView: UIAlertAction!){

var code: String = self.codeTextField!.text;
var number: String = self.numberTextField!.text;

}

var inputFrame = CGRectMake(0, 70, 270, 25);
var inputView: UIView = UIView(frame: inputFrame);

var prefixFrame = CGRectMake(7, 5, 10, 10);
var prefixLabel: UILabel = UILabel(frame: prefixFrame);
prefixLabel.text = "+";

var codeFrame = CGRectMake(20, 0, 65, 25);
var countryCodeTextField: UITextField = UITextField(frame: codeFrame);
countryCodeTextField.placeholder = "Code";
countryCodeTextField.borderStyle = UITextBorderStyle.RoundedRect;
countryCodeTextField.keyboardType = UIKeyboardType.DecimalPad;

var numberFrame = CGRectMake(90, 0, 170, 25);
var myNumberTextField: UITextField = UITextField(frame: numberFrame);
myNumberTextField.placeholder = "Number - digits only";
myNumberTextField.borderStyle = UITextBorderStyle.RoundedRect;
myNumberTextField.keyboardType = UIKeyboardType.DecimalPad;

self.codeTextField = countryCodeTextField;
self.numberTextField = myNumberTextField;

inputView.addSubview(prefixLabel);
inputView.addSubview(self.codeTextField!);
inputView.addSubview(self.numberTextField!);

alert.view.addSubview(inputView);


alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler:handleOk));

self.presentViewController(alert, animated: true, completion: nil);

} }

关于ios - 是否可以在 UIAlertController 的一行中插入两个文本字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26908142/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com