Today, I want to make a button. I don't mean anything about using the system. I don't feel like I can't learn new things. So I made a uiview myself (I used to do Symbian for neural work, and I like to do it myself, make controls by yourself.
There are two ways to draw a rectangle with rounded corners:
1. Directly modify the view style. The system provides the following:
View. layer. cornerradius = 6;
View. layer. maskstobounds = yes;
It's easy to use layer. This requires inverted databaseQuartzcore. Framework;
2. Draw a rounded rectangle in the view
Cgfloat radius = 20.0;
Cgcontextref context = uigraphicsgetcurrentcontext ();
Cgcontextsetrgbstrokecolor (context, 1.0, 1.0, 1.0, 1 );
Cgfloat Minx = cgrectgetminx (rect), midx = cgrectgetmidx (rect), Maxx = cgrectgetmaxx (rect );
Cgfloat miny = cgrectgetminy (rect), midy = cgrectgetmidy (rect), Maxy = cgrectgetmaxy (rect );
Cgcontextmovetopoint (context, Minx, midy );
Cgcontextaddarctopoint (context, Minx, miny, midx, miny, radius );
Cgcontextaddarctopoint (context, Maxx, miny, Maxx, midy, radius );
Cgcontextaddarctopoint (context, Maxx, Maxy, midx, Maxy, radius );
Cgcontextaddarctopoint (context, Minx, Maxy, Minx, midy, radius );
Cgcontextclosepath (context );
Cgcontextdrawpath (context, kcgpathfill );
Use the paint brush method in drawrect.
I hope that everyone will not meet the current situation, so they will not be eliminated by using XIB and thinking more.