2016-02-25 103 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; 
} 
相關問題