Skip to content

Instantly share code, notes, and snippets.

@sthewissen
Last active September 9, 2017 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sthewissen/d3c66d134c58f1d2fbd7593f1fb78e80 to your computer and use it in GitHub Desktop.
Save sthewissen/d3c66d134c58f1d2fbd7593f1fb78e80 to your computer and use it in GitHub Desktop.
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