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 a reverse database of QuartzCore. 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.
From the column diqun1314