Last active
September 9, 2017 14:30
-
-
Save sthewissen/d3c66d134c58f1d2fbd7593f1fb78e80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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