2016-02-25 82 views
1

我想圆角半径只有底角左右。我已经做到了,但底部的形状看起来不像确切的圆,所以我怎么能解决这个问题图像圆角半径只有左下角和右侧

enter image description here

+0

展我的代码... –

+0

看看下面的链接[Link1](http://stackoverflow.com/questions/25616382/how-to-set-cornerradius-for-only-bottom-left-bottom-right-and-top - 左转角),[Link2](http://stackoverflow.com/questions/29618760/create-a-rectangle-with-just-two-rounded-corners-in-swift/3562173 6#35621736) –

+0

查看此链接http://stackoverflow.com/questions/10167266/how-to-set-cornerradius-for-only-top-left-and-top-right-corner-of-a-uiview也许它会对你有帮助。 – JigneshP

回答

3
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.imageView.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(10.0, 10.0)]; 

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; 
maskLayer.frame = self.imageView.bounds; 
maskLayer.path = maskPath.CGPath; 
self.imageView.layer.mask = maskLayer; 
+0

好吧我用你的代码,并给CGSizeMake(150.0, 150.0)]但结果相同看起来我的形象在底部不是确切的圆形,当这段代码运行在iPhone 6的宽度和高度相同,它需要一些宽度的空间。 –

0

我有同样的问题,我解决了它这样的:

- (void)setMaskTo:(UIView*)view { 
CAShapeLayer *rect = [[CAShapeLayer alloc] init]; 
[rect setFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height/2)]; 
rect.backgroundColor = ([UIColor grayColor]).CGColor; 

UIBezierPath *shape = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0,rect.frame.size.height/2,self.view.frame.size.width,self.view.frame.size.height/2)]; 
CAShapeLayer *shapeLayer = [CAShapeLayer layer]; 
shapeLayer.path = shape.CGPath; 
shapeLayer.fillColor = [UIColor grayColor].CGColor; 

CAShapeLayer *viewMask = [[CAShapeLayer alloc] init]; 
[viewMask addSublayer:shapeLayer]; 
[viewMask addSublayer:rect]; 

view.layer.mask = viewMask; 
} 
相关问题