Xamarin表单中的反向进度栏

时间:2018-10-22 21:51:57

标签: xamarin xamarin.forms xamarin.ios

我已使用SO问题here在iOS中创建了一个反向进度栏(从右开始)。那是其他SO问题和我的问题之间的唯一区别。但是,我看不到添加为子视图的标签“ Hello”。

    void Setup()
    {
        BackgroundColor = UIColor.Clear;

        Layer.CornerRadius = 30;
        Layer.BackgroundColor = Color.LightGreen.ToCGColor();

        progressLayer = new CAShapeLayer()
        {
            FillColor = Color.FromHex("#1A4694").ToCGColor(),
            Frame = Bounds
        };

        Layer.AddSublayer(progressLayer);

        label = new UILabel(Bounds)
        {
            TextAlignment = UITextAlignment.Center,
            TextColor = UIColor.White,
            BackgroundColor = UIColor.Clear,
            Font = UIFont.FromName("ChalkboardSE-Bold", 20),
            Text = "Hello"
        };
        InsertSubview(label, 100);
    }

    double complete;
    public double Complete
    {
        get { return complete; }
        set { complete = value; SetNeedsDisplay(); }
    }

    public override void Draw(CGRect rect)
    {
        base.Draw(rect);
        var progressWidth = (rect.Width - (Layer.BorderWidth * 2)) * (1 - complete);
        var progressRect = new CGRect(rect.X + progressWidth, rect.Y + Layer.BorderWidth, rect.Width - progressWidth, (rect.Height - Layer.BorderWidth * 2));
        progressLayer.Path = UIBezierPath.FromRoundedRect(progressRect, (UIRectCorner.TopRight | UIRectCorner.BottomRight), new CGSize(30, 30)).CGPath;

    }
}

enter image description here

0 个答案:

没有答案