2013-04-05 54 views
0

我正面临一个非常奇怪的问题。我正在尝试将UIbuttons添加到Monotouch中的UIscrollview。但UIbutton没有得到显示。无法添加UIbutton到单击动态中的UIscrollview动态

下面是代码:

UIImage img = UIImage.FromFile("ecu.png"); 
UIButton btn = UIButton.FromType(UIButtonType.Custom); 
btn.SetBackgroundImage(img,UIControlState.Normal); 
btn.Frame = new RectangleF(UIScreen.MainScreen.Bounds.Size.Width - 185, 0, 185,UIScreen.MainScreen.Bounds.Size.Height, 100, 150, 150); 
btn.TouchUpInside += (sender, e) => { 
UIAlertView alert = new UIAlertView("Info","Tapped",null,"Ok",null); 
      alert.Show(); 
     } ; 
scrollimages.AddSubview (btn); 

相同的代码工作,如果我将按钮添加到视图。 我可以得到一些这方面的帮助。

+0

您是否设置了UIScrollView.ContentSize? – 2013-04-05 09:16:17

回答

0

我只是想下面的代码添加一个UIScrollView在Interface Builder中的查看后:

UIImage img = UIImage.FromFile("ecu.png"); 
     UIButton btn = UIButton.FromType(UIButtonType.Custom); 
     btn.SetBackgroundImage(img,UIControlState.Normal); 
     btn.Frame = new RectangleF(0.0f, 0.0f, 150.0f, 150.0f); 
     btn.TouchUpInside += (sender, e) => { 
      UIAlertView alert = new UIAlertView("Info","Tapped",null,"Ok",null); 
      alert.Show(); 
     } ; 
     this.ScrollImages.AddSubview (btn); 

,它按预期工作。奇怪的事情似乎是你有7个RectangleF构造函数的参数。你刚刚尝试将原点设置为0,0来查看是否在那里添加了一个按钮?

+0

感谢您的回答。它现在有效。我把x和y的坐标设置为0,它的工作正常 – user2122350 2013-04-05 10:40:15

+0

嘿,只是一个小小的疑问。我已经使用\t \t为相同的UIscrollview添加了一个UIImageView imageView.Frame = new System.Drawing.RectangleF(UIScreen.MainScreen.Bounds.Size.Width - 150,yadjustment,150,150); \t \t \t imageView.UserInteractionEnabled = true; \t \t \t imageView.Tag = position; \t \t \t \t \t \t scrollimages.AddSubview(imageView);图像视图被添加到循环旋转的滚动视图中。但同样的框架,如果我给UIbutton它失败。任何想法为什么? – user2122350 2013-04-05 11:14:16

+0

以何种方式失败? – Blounty 2013-04-05 11:27:35