Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using SampleApp.iOS.Effects;
[assembly: ResolutionGroupName("SuperAwesome")]
[assembly: ExportEffect(typeof(CatEffect), "CatEffect")]
namespace SampleApp.iOS.Effects
{
public class CatEffect : PlatformEffect
{
protected override void OnAttached()
{
try
{
if (Control is UITextField)
{
// Set the border style to none to show background image.
(Control as UITextField).BorderStyle = UITextBorderStyle.None;
// Create an image and set it as background pattern.
var image = UIImage.FromBundle("cat.jpg").CreateResizableImage(new UIEdgeInsets(0, 10, 0, 10), UIImageResizingMode.Stretch);
Control.BackgroundColor = UIColor.FromPatternImage(image);
}
}
catch (Exception ex)
{
Console.WriteLine("Cannot set property on attached control. Error: ", ex.Message);
}
}
protected override void OnDetached()
{
// Back to white.
Control.BackgroundColor = UIColor.White;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment