我正在使用此代码UIButtons
在 a中添加 3 UIView
,然后将它们添加到我的屏幕上。
UIView buttonsContainerView = new UIView (new Rectangle (0,0,(int) this.View .Frame .Width ,40));
UIButton b;
for(int i=0;i<3;i++){
b= new RltTabBarButton ();
b.ImageEdgeInsets = new UIEdgeInsets (5,5,5,100);
if(i==0){
b.SetBackgroundImage (UIImage .FromFile ("ProjectRes/Images/Placeholder.png"),
UIControlState.Normal );
b.TitleLabel .Text = "Details";
b.Frame = new RectangleF (0,350,108,40);
b.Enabled =true ;
}else if(i==1){
b.SetBackgroundImage (UIImage .FromFile ("ProjectRes/Images/Placeholder.png"),
UIControlState.Normal );
b.TitleLabel .Text = "Map";
b.Frame = new RectangleF (110,350,100,40);
b.Enabled =true ;
}else if(i==2){
b.SetBackgroundImage (UIImage .FromFile ("ProjectRes/Images/Placeholder.png"),
UIControlState.Normal );
b.TitleLabel .Text = "Agent";
b.Frame = new RectangleF (212,350,108,40);
b.Enabled =true ;
}
buttonsContainerView .AddSubview (b);
}
this.View .AddSubview (buttonsContainerView );
当我运行我的应用程序时。添加到正确位置的按钮。但他们Text
的TitleLable
. 虽然我设置了这个项目。而且它们看起来像一些图像,因此我无法单击它们并与它们进行交互。
我设置了他们的Enabled
字段true
,但没有任何更改。
编辑:根据答案,我将代码更改为:
UIView buttonsContainerView = new UIView (new Rectangle (0,0,(int) this.View .Frame .Width ,40));
UIButton DetailsButton= new UIButton (UIButtonType.RoundedRect );
DetailsButton.ImageEdgeInsets = new UIEdgeInsets (5,5,5,100);
DetailsButton.SetBackgroundImage (UIImage .FromFile ("ProjectRes/Images/Placeholder.png"),
UIControlState.Normal );
DetailsButton.SetTitle ("Details",UIControlState.Normal );
DetailsButton.Frame = new RectangleF (0,350,108,40);
buttonsContainerView .AddSubview (DetailsButton);
UIButton MapButton= new UIButton (UIButtonType.RoundedRect );
MapButton.ImageEdgeInsets = new UIEdgeInsets (5,5,5,100);
MapButton.SetBackgroundImage (UIImage .FromFile ("ProjectRes/Images/Placeholder.png"),
UIControlState.Normal );
MapButton.SetTitle ("Map",UIControlState.Normal );
MapButton.Frame = new RectangleF (110,350,100,40);
buttonsContainerView .AddSubview (MapButton);
UIButton AgentButton= new UIButton (UIButtonType.RoundedRect );
AgentButton.SetBackgroundImage (UIImage .FromFile ("ProjectRes/Images/Placeholder.png"),
UIControlState.Normal );
AgentButton.SetTitle ("Agent",UIControlState.Normal );
AgentButton.Frame = new RectangleF (212,350,108,40);
buttonsContainerView .AddSubview (AgentButton);
this.View .AddSubview (buttonsContainerView );
但没有任何变化。我们无法点击按钮。它们看起来像图像。我相信它buttonsContainerView
与EnableInputClicksWhenVisible
. 当我在这个视图中调试应用程序时,调试器在想要执行它的值时会有一些异常。我能够复制这个的头:
MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[UIView enableInputClicksWh…
我不知道如何解决它。