Hello everyone,
I'm currently trying to implement customs controls (Buttons, Labels, etc.) which looks and behave on all plattform similar.
I startet with Android and a custom button, which works fine. Now I'm trying to implement the same on iOS and I have one issue.
The button should be green with white text and on click the button should be in a darker green, but same text color.
I tried to implement on iOS the following ButtonRenderer:
class OBButtonRenderer : ButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.SetBackgroundImage(ImageWithColor(Color.Green), UIControlState.Normal);
Control.SetBackgroundImage(ImageWithColor(Color.Lime), UIControlState.Highlighted);
}
}
private UIImage ImageWithColor(Color color)
{
var rect = new RectangleF(0, 0, 1, 1);
UIGraphics.BeginImageContext(rect.Size);
var context = UIGraphics.GetCurrentContext();
context.SetFillColorWithColor(color.ToCGColor());
context.FillRect(rect);
var image = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
return image;
}
}
Now I have the issue that the Highlighted image is on top of the normal image, so that the button is not in Lime, more in something between and the text is getting green.
I tried to implement a iOS only Xamarin App and if I set the ButtonType to Custom, then it works. But how can I set the ButtonType in the Renderer?
Thanks for the help.
kind regards
Martin