private void Paint(RoundedLabel view)
        {
            if (view == null)
            {
                return;
            }

            var curvedBackgroundColor = view.CurvedBackgroundColor.ToAndroid();
            var curvedBorderColor     = view.CurvedBorderColor.ToAndroid();
            var curvedBorderWidth     = (int)Math.Round(view.CurvedBorderWidth);

            // creating gradient drawable for the curved background
            _gradientBackground = new GradientDrawable();
            _gradientBackground.SetShape(ShapeType.Rectangle);
            _gradientBackground.SetColor(curvedBackgroundColor);

            // Thickness of the stroke line
            _gradientBackground.SetStroke(curvedBorderWidth, curvedBorderColor);

            //// Radius for the curves
            _gradientBackground.SetCornerRadius(
                DpToPixels(this.Context,
                           Convert.ToSingle(view.CurvedCornerRadius)));

            // set the background of the label
            Control.SetBackground(_gradientBackground);
        }
        private void Paint(RoundedLabel view)
        {
            if (view == null)
            {
                return;
            }

            this.Layer.BackgroundColor = view.CurvedBackgroundColor.ToCGColor();
            this.Layer.BorderColor     = view.CurvedBorderColor.ToCGColor();
            this.Layer.BorderWidth     = (float)view.CurvedBorderWidth;
            this.Layer.CornerRadius    = (float)view.CurvedCornerRadius / 2f;
        }
Esempio n. 3
0
        public MainPage()
        {
            InitializeComponent();

            var roundedLabel = new RoundedLabel
            {
                TextColor             = Color.White,
                CurvedBackgroundColor = Color.Red,
                Text = "RoundedLabel",
                RoundedCornerRadius     = 20,
                HorizontalTextAlignment = TextAlignment.Center,
                HorizontalOptions       = LayoutOptions.FillAndExpand,
                VerticalOptions         = LayoutOptions.FillAndExpand,
                VerticalTextAlignment   = TextAlignment.Center,
                // HeightRequest = 0,
                FontSize       = 15,
                FontAttributes = FontAttributes.Bold
            };

            var relativeLayout = new RelativeLayout();

            double GetRoundedLabelWidth(RelativeLayout parent) =>
            roundedLabel.Measure(parent.Width, parent.Height).Request.Width + 80;

            double GetRoundedLabelHeight(RelativeLayout parent) =>
            roundedLabel.Measure(parent.Width, parent.Height).Request.Height + 30;

            relativeLayout.Children.Add(
                roundedLabel,
                Constraint.RelativeToParent(parent => parent.Width / 2 - (GetRoundedLabelWidth(parent)) / 2),
                Constraint.Constant(0),          //Constraint.RelativeToParent(parent => parent.Height / 2 - (GetRoundedLabelHeight(parent) + 30) / 2),
                Constraint.RelativeToParent(layout => GetRoundedLabelWidth(layout))
                //,Constraint.RelativeToParent(layout => GetRoundedLabelHeight(layout) + 30)
                );
            relativeLayout.Padding = new Thickness(80, 0);

            RoundedLabelView.Content = relativeLayout;
        }