Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin.ios 在monotouch中使用CoreGraphics创建按钮_Xamarin.ios_Core Graphics - Fatal编程技术网

Xamarin.ios 在monotouch中使用CoreGraphics创建按钮

Xamarin.ios 在monotouch中使用CoreGraphics创建按钮,xamarin.ios,core-graphics,Xamarin.ios,Core Graphics,我正在尝试在monotouch上创建一个带有CoreGraphics的按钮。我不知道按下按钮时如何改变按钮的颜色。我试图覆盖触摸开始和触摸结束方法,但我不知道如何更改颜色。可以用两种方法处理背景颜色。您可以简单地设置BackgroundColor属性。这将自动更改颜色。或者,如果将颜色存储为用于FillRect的私有变量,则需要调用SetNeedsDisplay以强制调用Draw 公共覆盖空TouchesBegan(单调基础.NSET触碰,uiviv-EVT) { base.touchesbea

我正在尝试在monotouch上创建一个带有CoreGraphics的按钮。我不知道按下按钮时如何改变按钮的颜色。我试图覆盖
触摸开始
触摸结束
方法,但我不知道如何更改颜色。

可以用两种方法处理背景颜色。您可以简单地设置BackgroundColor属性。这将自动更改颜色。或者,如果将颜色存储为用于FillRect的私有变量,则需要调用SetNeedsDisplay以强制调用Draw

<代码>公共覆盖空TouchesBegan(单调基础.NSET触碰,uiviv-EVT) { base.touchesbeated(touchs,evt); this.BackgroundColor=UIColor.Green; 背景色2=UIColor.黄色; this.SetNeedsDisplay(); } 公共覆盖空隙TouChESDATE(单调基础.NSET触控,uiviv-EVT) { base.touchesend(触摸,evt); this.BackgroundColor=UIColor.Red; backColor2=UIColor.Blue; this.SetNeedsDisplay(); } 公共覆盖无效绘制(矩形F矩形) { 基础绘制(rect); 使用(CGContext=UIGraphics.GetCurrentContext()){ 矩形f rect2=此.Bounds; rect2.X+=10; rect2.Y+=5; rect2.宽度-=20; rect2.高度-=10; backColor2.SetFill(); context.FillRect(rect2); } }
您是否使用呼叫setBackgroundImage:forState:with UIControlStateSelected。更好的是,Xamarin我正在用coregraphics做所有事情。只是子类化uiview并覆盖draw methodMan,你救了我的命。我找不到需要显示的设置。谢谢