问题描述:在代码中使用UIProgressView 设置了Progress Image和Track Image没能正常的工作?
画不多说先放效果图:
Progress Image:
Track Image:
效果图:
解决方法:
这个问题是ios的bug,不必在意,只要重新建个子类继承UIProgressView,并添加两个属性分别是:
@property (nonatomic,strong)UIImage *ggTrackImage;
@property (nonatomic,strong)UIImage *ggProgressImage;
分别在set方法里对UIProgressView自带的trackImage,和ProgressImge进行赋值,都说了ios的bug就不能直接拿到属性进行赋值了,取出UIProgressView的SubViews,并根据自己的需求对图片进行拉伸,我这里选择的是平滑拉伸,代码如下:
-(void)setGgTrackImage:(UIImage *)ggTrackImage
{_ggTrackImage=ggTrackImage;
UIImageView *trackImageView=self.subviews.firstObject;
CGRect trackProgressFrame=trackImageView.frame;
trackProgressFrame.size.height=self.frame.size.height;
trackImageView.frame=trackProgressFrame;
CGFloat width = _ggTrackImage.size.width/2.0;
CGFloat height = _ggTrackImage.size.height/2.0;
UIImage *imgTrack = [_ggTrackImage resizableImageWithCapInsets:UIEdgeInsetsMake(height, width, height, width)];
trackImageView.image=imgTrack;}
-(void)setGgProgressImage:(UIImage *)ggProgressImage
{_ggProgressImage=ggProgressImage;
CGFloat width = _ggProgressImage.size.width/2.0;
CGFloat height = _ggProgressImage.size.height/2.0;
UIImageView *progressImageView=self.subviews.lastObject;
CGRect ProgressFrame=progressImageView.frame;
ProgressFrame.size.height=self.frame.size.height;
progressImageView.frame=ProgressFrame;
UIImage *imgProgress = [_ggProgressImage resizableImageWithCapInsets:UIEdgeInsetsMake(height, width, height, width)];progressImageView.image=imgProgress;}
网友评论