public static UIImage CreateCappedUIImage(string imageResource, bool flipHorizontally, bool flipVertically, Color tintColor, TintColorModes mode, Thickness capWidth) { Console.WriteLine("Creating UIImage '{0}', FlipHorizontally={1}, FlipVertically={2}", imageResource, flipHorizontally, flipVertically); if (tintColor != Color.Default) { Console.WriteLine(" TintColor={0}", tintColor); } if (capWidth.IsNotSet()) { Console.WriteLine(" Cap.Left={0}, Cap.Top={1}, Cap.Right={2}, Cap.Bottom={3}", capWidth.Left, capWidth.Top, capWidth.Right, capWidth.Bottom); } var image = new UIImage(imageResource); Thickness adjustedCapWidth = capWidth; if (flipHorizontally || flipVertically) { var orientation = GetOrientation(flipHorizontally, flipVertically); image = new UIImage(image.CGImage, image.CurrentScale, orientation); if (!capWidth.IsNotSet()) { if (flipHorizontally) { var left = adjustedCapWidth.Left; adjustedCapWidth.Left = adjustedCapWidth.Right; adjustedCapWidth.Right = left; } if (flipVertically) { var top = adjustedCapWidth.Top; adjustedCapWidth.Top = adjustedCapWidth.Bottom; adjustedCapWidth.Bottom = top; } } } if (tintColor != Color.Default) { image = ApplyTintEffect(image, tintColor.ToUIColor(), mode); } if (!capWidth.IsNotSet()) { var capInsets = adjustedCapWidth.ToUIEdgeInsets(); image = image.CreateResizableImage(capInsets, UIImageResizingMode.Stretch); } return(image); }