2011-12-12 22 views
0

我有一個圓角的視圖。 我想讓它在視圖的兩個底角處圓角。 我該怎麼做?setRadiusCorner只是在視圖的底部

這是我的代碼,使圓角的觀點:

CALayer *myLayer = moreInfoView.layer; 
[myLayer setCornerRadius:20.0]; 
[view.layer setMasksToBounds:YES]; 

這可能嗎?

謝謝!

回答

0

不要以爲你可以輕鬆地用CALayer做到這一點 - 你可以繼承NSView並做一個簡單的重繪例程。可能是最容易使用http://www.cocoadev.com/index.pl?RoundedRectangles作爲出發點(去掉兩個貝塞爾路徑後,你不希望有四捨五入),然後做一個簡單:

- (void)drawRect:(CGRect)rect 
{ 
    self.layer.masksToBounds = NO; 
    self.layer.shadowColor = [[UIColor xxxx] CGColor]; 
    self.layer.shadowOffset = CGSizeMake(0,2); 
    self.layer.shadowRadius = ... 
    self.layer.shadowOpacity = ... 

    UIBezierPath *path = [UIBezierPath bezierPathWithPartiallyRoundedRect:rect 
      byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(20, 20)]; 
    [[UIColor blackColor] setFill or Stroke]; 

    [path stroke or fill]; 
} 

在上面的鏈接 - 第二個簡單的例子,使您的生活更輕鬆 - 你可以簡單地讓他們兩個'路徑lineToPoint:..'。

+0

感謝德克!但我覺得很難實現..對不起,我在所有的xcode的東西:) 我可以告訴你,我有一個視圖,我在xib文件和視圖的變量稱爲「moreInfoView」的圖形。 你能想我該怎麼做?謝謝 –

3

回合只有UIRectCornerBottomLeftUIRectCornerBottomRight角落:

UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:yourView.bounds 
              byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) 
               cornerRadii:CGSizeMake(5.0, 5.0)]; 

CAShapeLayer *layer = [CAShapeLayer layer]; 
layer.frame = yourView.bounds; 
layer.path = path.CGPath; 
yourView.layer.mask = layer;