public static UIColor ToUIColor(this Color color, Color defaultColor) { if (color.IsDefault) return defaultColor.ToUIColor(); return color.ToUIColor(); }
protected override void SetBackgroundColor(Color color) { if (_refreshControl == null) { return; } _refreshControl.BackgroundColor = color?.ToUIColor(); }
public static async Task<ImageSource> AddText(this StreamImageSource source, string text, PointF 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 Func<Stream>(() => new MemoryStream(bytes))); }
void UpdateThumbColor() { if (Element == null) { return; } Color thumbColor = Element.ThumbColor; Control.ThumbTintColor = thumbColor?.ToUIColor() ?? _defaultThumbColor; }
protected virtual void SetBackgroundColor(Color color) { if (color == Color.Default) #if __MOBILE__ { BackgroundColor = _defaultColor; } else { BackgroundColor = color.ToUIColor(); } #else { Layer.BackgroundColor = _defaultColor.CGColor; }
protected virtual void SetBackgroundColor(Color color) { if (color == Color.Default) { BackgroundColor = _defaultColor; } else { BackgroundColor = color.ToUIColor(); } }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); if (e.PropertyName == "Renderer") { UpdateItemState(); } if (e.PropertyName == "Dash") { if (((HighlightLabel)Element).Dash) { attributes.UnderlineStyle = NSUnderlineStyle.Single; } else { attributes.UnderlineStyle = NSUnderlineStyle.None; } Control.AttributedText = new NSMutableAttributedString(Control.Text, attributes); } if (e.PropertyName == "Highlight") { if (((HighlightLabel)Element).Highlight != null) { var color = Color.FromHex(((HighlightLabel)Element).Highlight).ToUIColor(); attributes.BackgroundColor = color; } else { attributes.BackgroundColor = UIColor.White; } Control.AttributedText = new NSMutableAttributedString(Control.Text, attributes); } if (e.PropertyName == "CellBackgroudColor") { Color color = ((HighlightLabel)Element).BackgroundColor; if (color.Equals(Color.White)) { attributes.BackgroundColor = UIColor.White; } else { attributes.BackgroundColor = color.ToUIColor(); } } SetNeedsDisplay(); }
protected override void SetBackgroundColor(Color color) { if (color == Color.Default) { BackgroundColor = UIColor.Clear; } else { BackgroundColor = color.ToUIColor(); } }
protected override void SetBackgroundColor(Color color) { base.SetBackgroundColor(color); if (Control == null) { return; } Control.TrackTintColor = color != Color.Default ? color.ToUIColor() : null; }
public void SetStatusBarColor(Color color) { UIView statusBar = UIApplication.SharedApplication.ValueForKey( new NSString("statusBar")) as UIView; if (statusBar != null && statusBar.RespondsToSelector( new ObjCRuntime.Selector("setBackgroundColor:"))) { statusBar.BackgroundColor = color.ToUIColor(); } }
void SetWebViewBackgroundColor(Color backgroundColor) { if (Control != null) { InvokeOnMainThread(() => { Control.BackgroundColor = backgroundColor.ToUIColor(); Element.BackgroundColor = backgroundColor; }); } }
public void ChangeStatusBarColor(Color color) { bool isColorDark = color.ToCGColor().IsColorDark(); //Status Bar property removed in iOS 13 //TODO: Implement statusBarManager when bindings available from Xamarin //if (@available(iOS 13, *)) //{ // UIView* statusBar = [[UIView alloc]initWithFrame:[UIApplication sharedApplication].keyWindow.windowScene.statusBarManager.statusBarFrame] ; // statusBar.backgroundColor = [UIColor redColor]; // [[UIApplication sharedApplication].keyWindow addSubview:statusBar]; //} if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0)) { System.nint tag = (System.nint) 38482458385; UIView statusBar = UIApplication.SharedApplication.KeyWindow?.ViewWithTag(tag); if (statusBar != null) { statusBar.BackgroundColor = color.ToUIColor(); } else { UIView statusBarView = new UIView(frame: UIApplication.SharedApplication.StatusBarFrame); statusBarView.Tag = tag; UIApplication.SharedApplication.KeyWindow?.AddSubview(statusBarView); statusBarView.BackgroundColor = color.ToUIColor(); } } else { UIApplication.SharedApplication.StatusBarStyle = isColorDark ? UIStatusBarStyle.LightContent : UIStatusBarStyle.Default; if (UIApplication.SharedApplication.RespondsToSelector(new ObjCRuntime.Selector("statusBar"))) { if (UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) is UIView statusBar) { statusBar.BackgroundColor = color.ToUIColor(); } } } }
private void UpdateColor() { Color textColor = Element.TextColor; if (!Element.IsEnabled) { Control.TextColor = _defaultTextColor; return; } Control.TextColor = textColor.ToUIColor(); }
public void SetBadge(Page page, ToolbarItem item, string value, Color backgroundColor, Color textColor) { Device.BeginInvokeOnMainThread(() => { var renderer = Platform.GetRenderer(page); if (renderer == null) { renderer = Platform.CreateRenderer(page); Platform.SetRenderer(page, renderer); } var vc = renderer.ViewController; var rightButtonItems = vc?.ParentViewController?.NavigationItem?.RightBarButtonItems; // If we can't find the button where it typically is check the child view controllers // as this is where MasterDetailPages are kept if (rightButtonItems == null && vc.ChildViewControllerForHomeIndicatorAutoHidden != null) { foreach (var uiObject in vc.ChildViewControllerForHomeIndicatorAutoHidden) { string uiObjectType = uiObject.GetType().ToString(); if (uiObjectType.Contains("FormsNav")) { UIKit.UINavigationBar navobj = (UIKit.UINavigationBar)uiObject; if (navobj.Items != null) { foreach (UIKit.UINavigationItem navitem in navobj.Items) { if (navitem.RightBarButtonItems != null) { rightButtonItems = navitem.RightBarButtonItems; break; } } } } } } var idx = page.ToolbarItems.IndexOf(item); if (rightButtonItems != null && rightButtonItems.Length > idx) { var barItem = rightButtonItems[idx]; if (barItem != null) { barItem.UpdateBadge(value, backgroundColor.ToUIColor(), textColor.ToUIColor()); } } }); }
public static void SetBorder(this MCard view, Color color, double width) { if (color == Color.Default) { view.SetBorderColor(UIColor.Clear, UIControlState.Normal); } else { view.SetBorderWidth((nfloat)width, UIControlState.Normal); view.SetBorderColor(color.ToUIColor(), UIControlState.Normal); } }
void SetUIImageViewTintColor(UIImageView imageView, Color color) { if (imageView.Image == null) { Element.PropertyChanged += ImageViewTintColorPropertyChanged; } else { imageView.Image = imageView.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate); imageView.TintColor = color.ToUIColor(); } }
public void SetBorder(double strokeWidth, Color strokeColor, GradientBrush gradientBrush) { _dirty = true; _strokeWidth = (float)strokeWidth; _strokeColor = strokeColor.ToUIColor(); _strokeGradientProvider?.Dispose(); _strokeGradientProvider = GradientProvidersContainer.Resolve( gradientBrush.GetType()); _strokeGradientProvider?.SetGradient(gradientBrush); SetNeedsDisplay(); }
void OverrideThemeColors() { Color minColor = Element.MinimumTrackColor; Color maxColor = Element.MaximumTrackColor; Color thumbColor = Element.ThumbColor; // jump out as we want the defaults if (minColor.IsDefault && maxColor.IsDefault && thumbColor.IsDefault) { return; } if (!minColor.IsDefault) { Control.SetTrackFillColor(minColor.ToUIColor(), UIControlState.Normal); // if no max color was specified, then use a shade of the min if (maxColor.IsDefault) { Control.GetTrackBackgroundColor(UIControlState.Normal).GetRGBA(out _, out _, out _, out var baseAlpha); Control.SetTrackBackgroundColor(minColor.MultiplyAlpha(baseAlpha).ToUIColor(), UIControlState.Normal); } if (thumbColor.IsDefault) { Control.SetThumbColor(minColor.ToUIColor(), UIControlState.Normal); } } if (!maxColor.IsDefault) { Control.SetTrackBackgroundColor(maxColor.ToUIColor(), UIControlState.Normal); } if (!thumbColor.IsDefault) { Control.SetThumbColor(thumbColor.ToUIColor(), UIControlState.Normal); } }
protected override void SetBackgroundColor(Color color) { if (Element == null) { return; } var elementColor = Element.BackgroundColor; _colorToRender = !elementColor.IsDefault ? elementColor.ToUIColor() : color.ToUIColor(); SetNeedsDisplay(); }
protected internal override void UpdatePlaceholderColor() { Color placeholderColor = Element.PlaceholderColor; if (placeholderColor.IsDefault) { _placeholderLabel.TextColor = _defaultPlaceholderColor; } else { _placeholderLabel.TextColor = placeholderColor.ToUIColor(); } }
private void SetBackgroundColorWithDefault(Color color, Color defaultColor) { if (color == Color.Default) { childView.BackgroundColor = defaultColor.ToUIColor(); } else { childView.BackgroundColor = color.ToUIColor(); } this.SetBackgroundColor(Color.Transparent); this.BackgroundColor = Color.Transparent.ToUIColor(); }
private void UpdateTitleColor() { var customPicker = Element as ExtendedPicker; Color placeholderColor = customPicker.PlaceholderColor; UIColor color = placeholderColor.ToUIColor(); var placeholderAttributes = new NSAttributedString(customPicker.Title, new UIStringAttributes() { ForegroundColor = color, }); Control.AttributedPlaceholder = placeholderAttributes; }
void UpdateColor() { var newColor = (Color)Element.GetValue(RoutingEffects.PickerColorEffect.ColorProperty); if (newColor == _color) { return; } _color = newColor; (Control as UITextField).AttributedPlaceholder = new Foundation.NSAttributedString((Control as UITextField).AttributedPlaceholder.Value, foregroundColor: _color.ToUIColor()); (Control as UITextField).TextColor = _color.ToUIColor(); }
protected override void SetBackgroundColor(Color color) { base.SetBackgroundColor(color); if (Control == null) { return; } if (_defaultTintColor == null) { if (Forms.IsiOS7OrNewer) { _defaultTintColor = Control.BarTintColor; } else { _defaultTintColor = Control.TintColor; } } if (Forms.IsiOS7OrNewer) { Control.BarTintColor = color.ToUIColor(_defaultTintColor); } else { Control.TintColor = color.ToUIColor(_defaultTintColor); } if (color.A < 1) { Control.SetBackgroundImage(new UIImage(), UIBarPosition.Any, UIBarMetrics.Default); } // updating BarTintColor resets the button color so we need to update the button color again UpdateCancelButton(); }
static void SetSearchBarIconColor(UIImageView imageView, Color targetColor, UIColor defaultTintColor) { var icon = imageView?.Image; if (icon == null || (targetColor.IsDefault && defaultTintColor == null)) { return; } var newIcon = icon.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate); imageView.TintColor = targetColor.IsDefault ? defaultTintColor : targetColor.ToUIColor(); imageView.Image = newIcon; }
protected override void SetBackgroundColor(Color color) { if (_backgroundView != null) { if (color == Color.Default) { _backgroundView.BackgroundColor = _defaultColor; } else { _backgroundView.BackgroundColor = color.ToUIColor(); } } }
public MKOverlayRenderer GetOverlayRenderer(MKMapView mapView, IMKOverlay overlay) { if (overlay is MKPolyline) { var polylineRenderer = new MKPolylineRenderer(overlay as MKPolyline); polylineRenderer.FillColor = _routeColor.ToUIColor(); polylineRenderer.StrokeColor = _routeColor.ToUIColor(); polylineRenderer.LineWidth = 8; return(polylineRenderer); } else if (overlay is MKPolygon) { var polygonRenderer = new MKPolygonRenderer(overlay as MKPolygon); polygonRenderer.FillColor = _formsMap.PolygonColor.ToUIColor(); polygonRenderer.StrokeColor = Xamarin.Forms.Color.Transparent.ToUIColor(); return(polygonRenderer); } return(null); }
public void SetStatusBarColor(Color color) { Device.BeginInvokeOnMainThread(() => { if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0)) { var statusBar = new UIView(UIApplication.SharedApplication.KeyWindow.WindowScene.StatusBarManager.StatusBarFrame) { BackgroundColor = color.ToUIColor() }; UIApplication.SharedApplication.KeyWindow.AddSubview(statusBar); } else { UIView statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView; if (statusBar.RespondsToSelector(new ObjCRuntime.Selector("setBackgroundColor:"))) { statusBar.BackgroundColor = color.ToUIColor(); } } UIApplication.SharedApplication.SetStatusBarStyle(UIStatusBarStyle.DarkContent, true); GetCurrentViewController().SetNeedsStatusBarAppearanceUpdate(); }); }
protected override void OnAttached() { var uiSwitch = Control as UISwitch; if (uiSwitch == null) { return; } trueColor = (Color)Element.GetValue(RoutingEffects.SwitchChangeColor.TrueColorProperty); falseColor = (Color)Element.GetValue(RoutingEffects.SwitchChangeColor.FalseColorProperty); if (falseColor != Color.Transparent) { uiSwitch.TintColor = falseColor.ToUIColor(); uiSwitch.Layer.CornerRadius = 16; uiSwitch.BackgroundColor = falseColor.ToUIColor(); } if (trueColor != Color.Transparent) { uiSwitch.OnTintColor = trueColor.ToUIColor(); } }
void UpdateBorder() { // NOTE: borders are not a "supported" style of the contained // button, thus we don't use the themer here. // BorderColor Color borderColor = Element.BorderColor; if (_defaultBorderColor == null) { _defaultBorderColor = Control.GetBorderColor(UIControlState.Normal); } if (borderColor.IsDefault) { Control.SetBorderColor(_defaultBorderColor, UIControlState.Normal); } else { Control.SetBorderColor(borderColor.ToUIColor(), UIControlState.Normal); } // BorderWidth double borderWidth = Element.BorderWidth; if (_defaultBorderWidth == -1) { _defaultBorderWidth = Control.GetBorderWidth(UIControlState.Normal); } // TODO: The Material button does not support borders: // https://github.com/xamarin/Xamarin.Forms/issues/4951 if (borderWidth > 1) { borderWidth = 1; } if (borderWidth == (double)Button.BorderWidthProperty.DefaultValue) { Control.SetBorderWidth(_defaultBorderWidth, UIControlState.Normal); } else { Control.SetBorderWidth((nfloat)borderWidth, UIControlState.Normal); } }
void UpdateTextColor() { if (_buttonScheme.ColorScheme is SemanticColorScheme colorScheme) { Color textColor = Element.TextColor; if (textColor.IsDefault) { colorScheme.OnPrimaryColor = _defaultButtonScheme.ColorScheme.OnPrimaryColor; } else { colorScheme.OnPrimaryColor = textColor.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, PointF 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))); }
public void SetBackground(Color color) { BackgroundColor = color.ToUIColor (); }
private void SetTintColor(Color tintColor) { if (tintColor == Color.Default) { Control.TintColor = null; if (Control.Image != null) Control.Image = Control.Image.ImageWithRenderingMode(UIImageRenderingMode.Automatic); } else { if (Control.Image != null) Control.Image = Control.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate); Control.TintColor = tintColor.ToUIColor(); } }