View Full Version : UIView Custom Drawing

Jul 22, 2008, 02:09 PM
Anyone have sample code or know how to draw a rounded rectangle (similar to the rounded rect UI Button, or the rounded view on a grouped table)

I want to draw custom data on a View, and want to keep the look consistent with the rest of the app. I want to frame it all in a rounded rectangle, as if it's in a button. Anyone know of sample code to do that?

Do you need to create small regions in each corner and draw quarter circles? Or is there a simple API to do that?

Or would you say I should just draw directly on an already rounded button?

Jul 22, 2008, 02:42 PM
If I try to draw on a rounded rectangle, I can't take advantage of the DrawRect function in the View...

argh... There should be a sample on this...

Jul 22, 2008, 02:49 PM
Doh! Nevermind - I see this in QuartzDemo...

Jul 23, 2008, 11:14 AM
As a follow up: Does anyone know how to draw custom text on a UIView?

I can draw graphics well enough based on samples - but when I follow the documentation to write text to the context, it doesn't show up. The color and alpha should show up on the background, but I'm afraid it's not showing.

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSelectFont(context, "Verdana", 10, kCGEncodingMacRoman);
CGContextSetCharacterSpacing (context, 10);
CGContextSetTextDrawingMode (context, kCGTextStroke);

CGContextSetRGBFillColor (context, 0, 0, 0, 0);
CGContextSetRGBStrokeColor (context, 0, 0, 0, 0);

CGContextShowTextAtPoint (context, 40, 40, "TestTest", 9);

Any help? Also - is there a better way of drawing text right on the context?

Any advice would be greatly appreciated...

Oct 23, 2008, 05:58 AM