|
|
![]() |
![]() |
|
LinkBack | Thread Tools | Display Modes | ![]() |
|
|
#1 (permalink) |
|
Junior Member
Join Date: Jul 2008
Posts: 26
|
Hi all,
I am creating a rect using CGRectMake and creating a table view by using initWithFrame. The problem is that it gives me a straight edge rectangle. How do i create a rectangle with a round edge. Any help would be appreciated. Thanks, Akshay Shah. |
|
|
|
|
|
#3 (permalink) |
|
Member
Join Date: Jun 2008
Posts: 56
|
I'll just post this in case it's useful for someone else, but this is the code I wrote to add the missing CGContextAddRoundedRect function:
Code:
You must Login or Register to view and contribute code! This is done to increase participation in helping one another out, if you have been helped please pass on the favor. void CGContextAddRoundedRect (CGContextRef c, CGRect rect, int corner_radius) {
int x_left = rect.origin.x;
int x_left_center = rect.origin.x + corner_radius;
int x_right_center = rect.origin.x + rect.size.width - corner_radius;
int x_right = rect.origin.x + rect.size.width;
int y_top = rect.origin.y;
int y_top_center = rect.origin.y + corner_radius;
int y_bottom_center = rect.origin.y + rect.size.height - corner_radius;
int y_bottom = rect.origin.y + rect.size.height;
/* Begin! */
CGContextBeginPath(c);
CGContextMoveToPoint(c, x_left, y_top_center);
/* First corner */
CGContextAddArcToPoint(c, x_left, y_top, x_left_center, y_top, corner_radius);
CGContextAddLineToPoint(c, x_right_center, y_top);
/* Second corner */
CGContextAddArcToPoint(c, x_right, y_top, x_right, y_top_center, corner_radius);
CGContextAddLineToPoint(c, x_right, y_bottom_center);
/* Third corner */
CGContextAddArcToPoint(c, x_right, y_bottom, x_right_center, y_bottom, corner_radius);
CGContextAddLineToPoint(c, x_left_center, y_bottom);
/* Fourth corner */
CGContextAddArcToPoint(c, x_left, y_bottom, x_left, y_bottom_center, corner_radius);
CGContextAddLineToPoint(c, x_left, y_top_center);
/* Done */
CGContextClosePath(c);
}
Here is how you would use it: Code:
You must Login or Register to view and contribute code! This is done to increase participation in helping one another out, if you have been helped please pass on the favor. CGContextSetRGBFillColor(c, 0, 1, 0, 1); CGContextAddRoundedRect(c, CGRectMake(10,200,50,50), 10); CGContextFillPath(c); CGContextSetLineWidth(c, 3); CGContextSetRGBStrokeColor(c, 0, 0, 0, 1); CGContextAddRoundedRect(c, CGRectMake(10,200,50,50), 10); CGContextStrokePath(c); |
|
|
|
|
|
#4 (permalink) |
|
Junior Member
Join Date: Jul 2008
Posts: 26
|
Hi,
Thanks for your replies... Actually the thing i am doing is like i have a table view on top and a web view at bottom. The webview is inititated with a frame(created using CGRectMake) Now i want this Frame to have rounded edges.. Thanks, Akshay. |
|
|
|
|
|
#5 (permalink) |
|
Junior Member
Join Date: May 2009
Posts: 1
|
I took the code from above and modified it to do what you are looking for. I have essentially the same need for my application.
You can find the code on my blog at The Software Maven: Rounding Corners on a UIView - Travis Jensen's Software Blog. Enjoy and thanks for the starting point on the drawing code! tj |
|
|
|
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Search Engine Friendly URLs by vBSEO 3.3.0 RC1 |


Forum
Register
Quick Links
Members
UserCP
Calendar
Search
FAQ



Linear Mode
