我想创建一个简单的、定制的加载栏,其中包含两个图像:一个用于实色背景的图像,一个用于对角线的图像。我是iOS的新手,所以我的方法是创建一个自定义UIView,它使用两个UIImageViews,每个图像使用一个动画块将对角线图像从左向右移动。
我之所以采用这种方法,是因为我已经熟悉UIImageViews和动画块。我的问题是..。
非常感谢你的智慧!
发布于 2012-11-14 18:12:28
让您的“实色背景”视图成为“对角线”imageView的容器视图。(对角线是背景的子视图)
然后在对角线子视图上设置'clipsToBounds‘= YES,并根据需要重新调整框架。(假设您的对角线imageView代表100%的进度)
如果加载栏imageView没有圆角,则只需使用CALayer的cornerRadius属性即可。
imageView.layer.cornerRadius = 6.0f;
发布于 2012-11-14 18:16:15
看看WNProgressView,它可能会做你需要的事情。
发布于 2012-11-15 17:05:01
您可以使用以下两种方法来实现这一点:
1-将该类导入代码#import <QuartzCore/QuartzCore.h>
中。
然后将以下两行添加到-(void)viewDidLoad
方法中,这样,在加载视图时,条形图将被四舍五入,或者您可以将其添加到希望该条开始四舍五入的位置。
barImageView.layer.cornerRadius = 10.0f;
barImageView.layer.masksToBounds = YES;
2.另一种方法是使用以下代码:
-(void)roundCorners:(UIRectCorner)rectCorner forView:(UIView*)view
{
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds
byRoundingCorners:rectCorner
cornerRadii:CGSizeMake(20.0, 20.0)];
// Create the shape layer and set its path
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = view.bounds;
maskLayer.path = maskPath.CGPath;
// Set the newly created shape layer as the mask for the image view's layer
view.layer.mask = maskLayer;
}
添加以下行和viewDidLoad,或从何处开始舍入条形图
[self roundCorners:UIRectCornerTopRight|UIRectCornerTopLeft|UIRectCornerBottomRight|UIRectCornerBottomLeft forView:[self.view.subviews objectAtIndex:0] withAngle:10];
https://stackoverflow.com/questions/13384606
复制相似问题