首页 > 解决方案 > Xamarin Forms 中的反向进度条

问题描述

我使用此处的 SO 问题在 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;

    }
}

在此处输入图像描述

标签: xamarinxamarin.formsxamarin.ios

解决方案


推荐阅读