How to change UI开发者_开发技巧Button HighLight Color using Monotouch?
There is no direct way to do this. You must subclass UIButton and draw it your self when is is highlighted. This is a simple example:
public class CustomButton : UIButton
{
public CustomButton(RectangleF frame)
{
this.Frame = frame;
this.AddObserver(this, new NSString("Highlighted"), NSKeyValueObservingOptions.New, IntPtr.Zero);
}
public override void ObserveValue (NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
{
if (keyPath.ToString() == "Highlighted")
{
this.SetNeedsDisplay();
}
}
public override void Draw (RectangleF rect)
{
base.Draw (rect);
if (this.Highlighted)
{
// Draw for highlighted
} else
{
// Draw for normal
}
}
}
I have translated this from this question, which has an Objective-C example: Here
One possible way to do this, you will need to create a highlighted image for the button then use:
btn.SetImage(UIImage.FromBundle("Images/btnHighlighted.png"), UIControlState.Highlighted);
I have done this in my previos anwser to post so check link that i already implemented UIButton HighLigh Color
精彩评论