您可以使用以下两种方式实现此目的:
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];