2011-03-09 59 views
1

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

回答

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); 
    } 

} 
+0

对不起,什么是FromBundle?我以前没有见过。很酷的解决方案。 – 2011-03-10 00:40:30

+0

该捆绑包是您的应用程序的zipfile。 FromBundle()方法会自动尝试加载图像以获得适当的屏幕分辨率,例如,您可以在您的dir中使用cat.png和[email protected],并在方法上说明UIImage.FromBundle( “猫”)。非常有用。 – 2011-03-10 01:06:16

3

使用叠加在进度条顶部的新图像创建UIImageView。最初只需将.hidden属性设置为YES,并在符合条件时将其更改为NO,从而使覆盖的UIImageView可见。