There are various fillets in iOS development, and the simplest way to add rounded corners to a control is to set the corner property for the view's layer: [Objective-c]View Source file copy code ?
| 12 |
self.blueView.layer.cornerRadius = 5.f; self.blueView.layer.masksToBounds = YES; |
This approach brings two questions:
- When the number of pictures is more, this method of adding rounded corners particularly consumes performance, such as in UITableViewCell
If you add too many rounded corners, you can even create visual lag.
- The number of rounded corners cannot be configured (only the four corners of the view are rounded) and a fillet size cannot be configured.
The first problem is that the system frequently calls the GPU's off-screen rendering (offscreen Rendering) mechanism due to too many cases, causing memory loss to be severe. More about the off-screen rendering of the detailed, you can see here , this article not much to repeat.
Second question, we can use Uibezierpath
to the perfect solution. The following is the sample code:
[Objective-c]View Source file copy code ?
| 1234567 |
uibezierpath *maskpath = [Uibezierpath bezierpathwithroundedrect: self .blueview.bounds byroundingcorners:uirectcornertopleft | Uirectcornerbottomleft Cornerradii:cgsizemake (20, 0)]; cashapelayer *masklayer = [[Cashapelayer alloc] init]; masklayer.frame = self .blueview.bounds; masklayer.path = Maskpath.cgpath; self .blueview.layer.mask = Masklayer; self .blueview.layer.cornerradius = 5.f; self .blueview.layer.maskstobounds = yes |
If you want to configure a corner to be rounded, you only need to specify the corresponding Uirectcorner
You can also use the following method: Take a pre-generated fillet picture, and cache this method is a better means. Preprocessing rounded pictures can be processed in the background, cached after processing, and then displayed in the main thread, which avoids unnecessary off-screen rendering. [Objective-c]View Source file copy code ?
| 1234 |
self .layer.cornerradius = 6; self .layer.maskstobounds = yes //cropping self .layer.shouldrasterize = yes //Cache self .layer.rasterizationscale = [UIScreen mainscreen].scale; |
When Shouldrasterize is set to true, the layer is rendered as a bitmap and cached, and will not be rendered again the next time it is used. The realization of the fillet itself is to do color mixing (blending), if every time the page comes out blending, consumption is too large, then shouldrasterize = yes, the next time is simply to read from the cache of the rendering engine that bitmap, savesystemResources. If you perform a fillet setting every time you scroll the TableView, you will definitely block the UI, and setting this will make the swipe smoother.
IOS Fillet those things