【发布时间】:2018-08-10 21:35:25
【问题描述】:
我是 Monotouch 的新手,已将以下代码添加到我的 SingleViewApplication。您可以在下面看到我的控制器代码,我试图在单击按钮后更改背景。
public partial class FirstViewAppViewController : UIViewController
{
public FirstViewAppViewController () : base ("FirstViewAppViewController", null)
{
}
UIButton buttonChangeColor;
private void CreateButton (){
RectangleF viewFrame = this.View.Frame;
RectangleF buttonFrame = new RectangleF (10f, viewFrame.Bottom -
200f, viewFrame.Width - 20f, 50f);
this.buttonChangeColor = UIButton.FromType
(UIButtonType.RoundedRect);
this.buttonChangeColor.Frame = buttonFrame;
this.buttonChangeColor.SetTitle ("Tap to change view color",
UIControlState.Normal);
this.buttonChangeColor.SetTitle ("Changing color...",
UIControlState.Highlighted);
this.buttonChangeColor.TouchUpInside +=
this.buttonChangeColor_TouchUpInside;
this.View.AddSubview (this.buttonChangeColor);
}
bool isRed;
private void buttonChangeColor_TouchUpInside (object sender, EventArgs e){
if (this.isRed) {
this.View.BackgroundColor = UIColor.LightGray;
this.isRed = false;
} else {
this.View.BackgroundColor = UIColor.Red;
this.isRed = true;
}
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
this.CreateButton();
// Perform any additional setup after loading the view, typically from a nib.
}
对我来说看起来不错,但我没有看到模拟器中的背景颜色发生变化。
有什么想法吗?谢谢。
【问题讨论】:
标签: xamarin.ios