将图像放在进度条上

时间:2011-03-09 21:27:32

标签: iphone xamarin.ios

我有一个进度条,当它达到100%时,如果给定一定条件,我想用一个与进度条大小相同的图像覆盖它。我不确定我是否需要UIImageView或UIImage。然后我将它作为子视图添加到具有进度条的View中,并设置框架以使其与进度条的坐标匹配?我之前没有做过这样的事情。

2 个答案:

答案 0 :(得分:3)

使用覆盖进度条顶部的新图像创建UIImageView。只需将.hidden属性设置为YES,当满足条件时,将其更改为NO,从而使覆盖的UIImageView可见。

答案 1 :(得分:1)

更好的设计是扩展UIProgressView类,如下所示。我没有测试过代码,因此请根据需要进行调整:

public class CustomUIProgressView: UIProgressView {
    public CustomUIProgressView(){

    }

    public override float Progress {
        get {
            return base.Progress;
        }
        set {
            base.Progress = value;
            if (value==1.0){
                showCompletionImage();
            }
        }
    }

    private void showCompletionImage(){
        var img = new UIImageView( UIImage.FromBundle("img"));
        img.Frame = new System.Drawing.RectangleF(0,0,this.Frame.Width, this.Frame.Height);
        this.AddSubview(img);
        this.BringSubviewToFront(img);
    }

}