2016-08-24 5 views
1

iOSでダイアログを表示し、ダイアログのビューにUITextViewを追加します。 UITextView textViewには、電子メール、電話、およびURLのクリック可能なリンク付きのテキストがあります。私はダイアログを起動することができますが、タイトルと[OK]ボタンだけを押してください。ダイアログビューにテキストビューが追加されていません。ここでの問題がtextviewであるか、またはビューがダイアログに追加されているかどうかはわかりません。サードパーティのライブラリを使用せずにUIAlertView(iOS、Xamarin)でUITextViewを追加

以下の私のコードを確認してください:

UITextView textView = new UITextView(); 
textView.Editable = false; 
textView.DataDetectorTypes = UIDataDetectorType.All; 
textView.Message = message; 
var dlg = UIAlertController.Create(Title ?? String.Empty, null, UIAlertControllerStyle.Alert); 
dlg.View.AddSubview(textView); 
dlg.AddAction(UIAlertAction.Create(OkText, UIAlertActionStyle.Default, action => Submit()));     

var top = Utils.GetTopViewController(); 
top.PresentViewController(dlg, animated: true, completionHandler: null); 

おかげで、

+0

http://stackoverflow.com/questions/23285750/adding-a-custom-view-to-a-alert-view –

答えて

7

はあなたが必要なものを完了するために、カスタムポップアップ表示を必要とするように、私はあなたのためのサンプルを作成し、これはコードであるようだ。

これはViewController.csです:

public partial class ViewController : UIViewController 
{ 
    public ViewController (IntPtr handle) : base (handle) 
    { 
    } 

    public override void ViewDidLoad() 
    { 
     this.View.BackgroundColor = UIColor.Gray; 
     this.View.AddGestureRecognizer (new UITapGestureRecognizer (() => { 
      CustomPopUpView cpuv = new CustomPopUpView (new CoreGraphics.CGSize (300, 200)); 
      cpuv.PopUp (true,delegate{ 
       Console.WriteLine("cpuv will close"); 
      }); 
     })); 
    } 
} 

そして、これはCustomPopUpView.csです:

public class CustomPopUpView : UIView 
{ 
    public delegate void PopWillCloseHandler(); 
    public event PopWillCloseHandler PopWillClose; 

    private UIVisualEffectView effectView = new UIVisualEffectView (UIBlurEffect.FromStyle (UIBlurEffectStyle.Dark)); 
    private UIButton btnClose = new UIButton (UIButtonType.System); 

    public CustomPopUpView (CGSize size) 
    { 
     nfloat lx = (UIScreen.MainScreen.Bounds.Width - size.Width)/2; 
     nfloat ly = (UIScreen.MainScreen.Bounds.Height - size.Height)/2; 
     this.Frame = new CGRect (new CGPoint (lx, ly), size); 

     effectView.Alpha = 0; 

     this.BackgroundColor = UIColor.White; 

     nfloat btnHeight = 40; 
     btnClose.SetTitle ("Close", UIControlState.Normal); 
     btnClose.Frame = new CGRect (0, this.Frame.Height - btnHeight, this.Frame.Width, btnHeight); 
     btnClose.TouchUpInside += delegate { 
      Close(); 
     }; 
     this.AddSubview (btnClose); 
    } 

    public void PopUp (bool animated = true, Action popAnimationFinish = null) 
    { 
     UIWindow window = UIApplication.SharedApplication.KeyWindow; 
     effectView.Frame = window.Bounds; 
     window.EndEditing (true); 
     window.AddSubview (effectView); 
     window.AddSubview (this); 

     if (animated) { 
      Transform = CGAffineTransform.MakeScale (0.1f, 0.1f); 
      UIView.Animate (0.15, delegate { 
       Transform = CGAffineTransform.MakeScale (1, 1); 
       effectView.Alpha = 0.8f; 
      },delegate { 
       if(null != popAnimationFinish) 
        popAnimationFinish(); 
      }); 
     } else { 
      effectView.Alpha = 0.8f; 
     } 
    } 

    public void Close (bool animated = true) 
    { 
     if (animated) { 
      UIView.Animate (0.15, delegate { 
       Transform = CGAffineTransform.MakeScale (0.1f, 0.1f); 
       effectView.Alpha = 0; 
      }, delegate { 
       this.RemoveFromSuperview(); 
       effectView.RemoveFromSuperview(); 
       if(null != PopWillClose) PopWillClose(); 
      }); 
     } else { 
      if(null != PopWillClose) PopWillClose(); 
     } 
    } 
} 

あなたはこのCustomPopUpViewにあなたが欲しいものを追加することができ、またはあなたはそれを継承し、独自のポップアップを作成することができます。

お手数ですがお手伝いします。

+0

の複製があります。ポップアップを閉じると、まだ画面に小さな白い領域が残っています私は 'Transform = CGAffineTransform.MakeScale(0.1f、0.1f);を' Transform = CGAffineTransform.MakeScale(0.01f、0.01f);に変更しました –

+0

大変申し訳ありませんが、削除するのを忘れてしまったので、クローズアニメーションが終了したら、コードを編集しました。ありがとうございました。@ FahadRehman –

関連する問題