2016-08-24 2 views
1

iOS에서 대화 상자를 표시하고 대화 상자보기에 UITextView을 추가하려고합니다. UITextView textView에는 이메일, 전화 및 URL에 대한 클릭 가능한 링크가 포함 된 텍스트가 있습니다. 제목과 확인 버튼 만 사용하여 대화 상자를 실행할 수 있습니다. 대화 상자보기에 텍스트보기가 추가되지 않습니다. 여기에 문제가 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.01f, 0.01f);) –

+0

죄송합니다. 제거하는 것을 잊었으므로 제거해야합니다. 가까운 애니메이션이 끝나면 코드를 편집했습니다. 감사합니다. @ FahadRehman –

관련 문제