public static void UpdateFromFormsControl (this UILabel uiLabel, string text, TextAlignment textAlignment, Color textColor, Font font) { uiLabel.Text = text; uiLabel.TextAlignment = textAlignment.ToUITextAlignment (); uiLabel.TextColor = textColor.ToUIColor (); uiLabel.Font = font.ToUIFont (); }
public static UIColor ToUIColor(this Color color, UIColor defaultColor) { if (color.IsDefault) return defaultColor; return color.ToUIColor(); }
/// <summary> /// Converts the UIColor to a Xamarin Color object. /// </summary> /// <param name="color">The color.</param> /// <param name="defaultColor">The default color.</param> /// <returns>UIColor.</returns> public static UIColor ToUIColorOrDefault(this Xamarin.Forms.Color color, UIColor defaultColor) { if (color == Xamarin.Forms.Color.Default) { return(defaultColor); } return(color.ToUIColor()); }
protected override void SetBackgroundColor(Xamarin.Forms.Color color) { if (color == Xamarin.Forms.Color.Default) { BackgroundColor = UIColor.Clear; } else { BackgroundColor = color.ToUIColor(); } }
/// <summary> /// Adds the text. /// </summary> /// <param name="source">The source.</param> /// <param name="text">The text.</param> /// <param name="point">The point.</param> /// <param name="font">The font.</param> /// <param name="color">The color.</param> /// <returns>Task<ImageSource>.</returns> public static async Task<ImageSource> AddText( this StreamImageSource source, string text, CGPoint point, Font font, Color color) { var token = new CancellationTokenSource(); var stream = await source.Stream(token.Token); var image = UIImage.LoadFromData(NSData.FromStream(stream)); var bytes = image.AddText(text, point, font.ToUIFont(), color.ToUIColor()).AsPNG().ToArray(); return ImageSource.FromStream(() => new MemoryStream(bytes)); }
void SetOverlay(Color color) { var formsImage = (Xamarin.Forms.Image)Element; if (formsImage?.Source == null || formsImage?.IsLoading == true) { return; } if (Control is UIImageView imageView && imageView.Image != null) { originalRenderingMode = imageView.Image.RenderingMode; originalTintColor = imageView.TintColor; imageView.Image = imageView.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate); imageView.TintColor = color.ToUIColor(); } }
protected override void SetBackgroundColor(Xamarin.Forms.Color color) { if (Element == null) { return; } var elementColor = Element.BackgroundColor; if (!elementColor.IsDefault) { _colorToRender = elementColor.ToUIColor(); } else { _colorToRender = color.ToUIColor(); } SetNeedsDisplay(); }
public static void UpdateFromFormsControl (this UILabel uiLabel, string text, Xamarin.Forms.TextAlignment textAlignment, Color textColor, Font font) { uiLabel.Text = text; switch (textAlignment) { case TextAlignment.Start: uiLabel.TextAlignment = UITextAlignment.Left; break; case TextAlignment.Center: uiLabel.TextAlignment = UITextAlignment.Center; break; case TextAlignment.End: uiLabel.TextAlignment = UITextAlignment.Right; break; } uiLabel.TextColor = textColor.ToUIColor (); uiLabel.Font = font.ToUIFont (); }
void SetOverlay(Xamarin.Forms.Color color) { var formsImage = (Xamarin.Forms.Image)Element; if (formsImage?.Source == null) { return; } try { UIImage image = ((UIImageView)Control).Image; UIImage coloredImage = null; UIGraphics.BeginImageContextWithOptions(image.Size, false, 0.0f); using (CGContext context = UIGraphics.GetCurrentContext()) { context.TranslateCTM(0, image.Size.Height); context.ScaleCTM(1.0f, -1.0f); //var rect = new RectangleF(0, 0, (float)(image.Size.Width * image.CurrentScale), (float)(image.Size.Height * image.CurrentScale)); var rect = new RectangleF(0, 0, (float)(image.Size.Width), (float)(image.Size.Height)); // draw image, (to get transparancy mask) context.SetBlendMode(CGBlendMode.Normal); context.DrawImage(rect, image.CGImage); // draw the color using the sourcein blend mode so its only draw on the non-transparent pixels context.SetBlendMode(CGBlendMode.SourceIn); context.SetFillColor(color.ToUIColor().CGColor); context.FillRect(rect); coloredImage = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); } ((UIImageView)Control).Image = coloredImage; } catch (ObjectDisposedException) { return; } }
protected override void OnAttached() { /* * Text Color change when I select a value */ _color = (Color)Element.GetValue(RoutingEffects.PickerChangeColor.ColorProperty); (Control as UITextField).AttributedPlaceholder = new Foundation.NSAttributedString((Control as UITextField).AttributedPlaceholder.Value, foregroundColor: _color.ToUIColor()); }
public static CGColor ToCGColor(this Color color) { return color.ToUIColor().CGColor; }
protected override void OnAttached() { (Control as UISwitch).OnTintColor = xfMainColor.ToUIColor(); }