【发布时间】:2011-06-02 06:12:51
【问题描述】:
我是 MonoTouch 4 新手,只是在窗口上尝试随机颜色,令我惊讶的是,下面显示的代码不起作用:
// 在 MainWindow.xib 文件中引用了名称 AppDelegate。 公共部分类 AppDelegate : UIApplicationDelegate { 随机 rand = new Random();
// This method is invoked when the application has loaded its UI and its ready to run
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
// If you have defined a view, add it here:
// window.AddSubview (navigationController.View);
objButton.TouchDown += HandleObjButtonTouchDown;
window.MakeKeyAndVisible ();
return true;
}
void HandleObjButtonTouchDown (object sender, EventArgs e)
{
float red, green, blue;
red = (float) rand.Next(100, 150);
green = (float) rand.Next(151, 200);
blue = (float) rand.Next(201, 255);
window.BackgroundColor = UIColor.Clear;
window.BackgroundColor = UIColor.FromRGB(red, green, blue);
objLabel.Text = red.ToString() + "," + blue.ToString() + "," + green.ToString();
}
每次单击按钮时,TouchDown 事件都会正确触发,并且标签会设置为随机的红色、绿色和蓝色值,但对窗口颜色没有任何影响。
请帮忙。
【问题讨论】:
标签: xamarin.ios