如何在Xamarin Forms中更改进度条的高度? [英] How to change height of progress bar in Xamarin Forms?

查看:112
本文介绍了如何在Xamarin Forms中更改进度条的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在代码中更改Xamarin Forms ProgressBar的高度?我正在使用Xamarin Forms V2.1.

How do I change the height of a Xamarin Forms ProgressBar in code? Am using Xamarin Forms V2.1.

.HeightRequest.MinimumHeightRequest似乎无效.默认进度条太细,甚至可能不会被注意到.

.HeightRequest and .MinimumHeightRequest seem to have no effect. The default progress bar is so thin that it might not even be noticed.

.BackgroundColor似乎也不起作用.

我在这里想念什么?

推荐答案

为此您需要自定义渲染器:

You need custom renderers for this:

首先为您的自定义进度栏创建一个类:

First create a class for your custom progress bar:

public class CustomProgressBar :ProgressBar
{
  public CustomProgressBar()
   {
   }
}

然后为您的自定义进度栏渲染器添加一个新文件:

And then also add a new file for your custom progress bar renderer:

对于iOS:

public class CustomProgressBarRenderer : ProgressBarRenderer
{
    protected override void OnElementChanged(
     ElementChangedEventArgs<Xamarin.Forms.ProgressBar> e)
    {
        base.OnElementChanged(e);

        Control.ProgressTintColor = Color.FromRgb(182, 231, 233).ToUIColor();// This changes the color of the progress
    }


    public override void LayoutSubviews()
    {
        base.LayoutSubviews();

        var X = 1.0f;
        var Y = 10.0f; // This changes the height

        CGAffineTransform transform = CGAffineTransform.MakeScale(X, Y);
        Control.Transform = transform;
    }
}

对于Android:

public class CustomProgressBarRenderer :ProgressBarRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.ProgressBar> e)
    {
        base.OnElementChanged(e);


        Control.ProgressTintList = Android.Content.Res.ColorStateList.ValueOf(Color.FromRgb(182, 231, 233).ToAndroid()); //Change the color
        Control.ScaleY = 10; //Changes the height

    }
}

希望这对您有所帮助!

这篇关于如何在Xamarin Forms中更改进度条的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆