IOS Fillet those things

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.