複数行の編集可能なテキストUITextview
をUIAlertController
の内部に作成するにはどうすればよいですか? UITextfield
は1行をサポートしており、ポップアップウィンドウで複数行のテキスト編集ボックスを作成する必要があります。複数行の編集可能なテキストUIAlertController内のUITextview?
5
A
答えて
8
これは、私がヴィシャルのアプローチにいくつかの調整をした...
func popUpController()
{
let alertController = UIAlertController(title: "\n\n\n\n\n\n", message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
let margin:CGFloat = 8.0
let rect = CGRectMake(margin, margin, alertController.view.bounds.size.width - margin * 4.0, 100.0)
let customView = UITextView(frame: rect)
customView.backgroundColor = UIColor.clearColor()
customView.font = UIFont(name: "Helvetica", size: 15)
// customView.backgroundColor = UIColor.greenColor()
alertController.view.addSubview(customView)
let somethingAction = UIAlertAction(title: "Something", style: UIAlertActionStyle.Default, handler: {(alert: UIAlertAction!) in print("something")
print(customView.text)
})
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: {(alert: UIAlertAction!) in print("cancel")})
alertController.addAction(somethingAction)
alertController.addAction(cancelAction)
self.presentViewController(alertController, animated: true, completion:{})
}
0
UIAlertController
に複数行のtextViewを作成することはできません。あなた自身のために自分自身を作成する必要がありますUIAlertController
。
+0
おかげでこれは私自身のカスタムを作るための良い方法は、最後に私は私の答えに、以下のようにそれを作る必要があり、です。おかげさまで、私に良いリンクをください。 – Vishal
2
良いappraochです。
- 初期のライトグレーのテキストをプレースホルダとして表示し、textViewDidBeginEditingで削除するためのUITextViewDelegateメソッドが追加されました。
textViewの境界線の幅、境界線の色、および背景色を設定して表示します。
class ViewController: UIViewController, UITextViewDelegate { ... @IBAction func showAlert(sender: AnyObject) { let alertController = UIAlertController(title: "Hello, I'm alert! \n\n\n\n\n\n\n", message: "", preferredStyle: .Alert) let rect = CGRectMake(15, 50, 240, 150.0) let textView = UITextView(frame: rect) textView.font = UIFont(name: "Helvetica", size: 15) textView.textColor = UIColor.lightGrayColor() textView.backgroundColor = UIColor.whiteColor() textView.layer.borderColor = UIColor.lightGrayColor().CGColor textView.layer.borderWidth = 1.0 textView.text = "Enter message here" textView.delegate = self alertController.view.addSubview(textView) let cancel = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil) let action = UIAlertAction(title: "Ok", style: .Default, handler: { action in let msg = (textView.textColor == UIColor.lightGrayColor()) ? "" : textView.text print(msg) }) alertController.addAction(cancel) alertController.addAction(action) self.presentViewController(alertController, animated: true, completion: {}) } func textViewDidBeginEditing(textView: UITextView) { if textView.textColor == UIColor.lightGrayColor(){ textView.text = "" textView.textColor = UIColor.darkGrayColor() } } }
+0
ありがとうございました。それはまさに私が求めていたものです。しかし、編集開始時には上がらない。そのための解決策はありますか? –
関連する問題
私はこのことについていくつかの研究をしました。 UIAlertControllerの内部実装が変更されたようです(私はIOS9で作業しています)。これは動作しません。ちょうどFYI。 –