Round Rect

CGPathRef NewPathWithRoundRect(CGRect rect, CGFloat cornerRadius)

{

//

// Create the boundary path

//

CGMutablePathRef path = CGPathCreateMutable();

CGPathMoveToPoint(path, NULL,

rect.origin.x,

rect.origin.y + rect.size.height - cornerRadius);

// Top left corner

CGPathAddArcToPoint(path, NULL,

rect.origin.x,

rect.origin.y,

rect.origin.x + rect.size.width,

rect.origin.y,

cornerRadius);

// Top right corner

CGPathAddArcToPoint(path, NULL,

rect.origin.x + rect.size.width,

rect.origin.y,

rect.origin.x + rect.size.width,

rect.origin.y + rect.size.height,

cornerRadius);

// Bottom right corner

CGPathAddArcToPoint(path, NULL,

rect.origin.x + rect.size.width,

rect.origin.y + rect.size.height,

rect.origin.x,

rect.origin.y + rect.size.height,

cornerRadius);

// Bottom left corner

CGPathAddArcToPoint(path, NULL,

rect.origin.x,

rect.origin.y + rect.size.height,

rect.origin.x,

rect.origin.y,

cornerRadius);

// Close the path at the rounded rect

CGPathCloseSubpath(path);

return path;

}

posted @ 2011-09-28 15:27  harvey.ding  阅读(265)  评论(0)    收藏  举报