IOS-Smooth Solution for setting the view rounded corner Style

Source: Internet
Author: User

IOS-Smooth Solution for setting the view rounded corner Style

Code

// Set the corner view style-(void) setUpSelfView {// Shadow self. layer. shadowColor = [UIColor blackColor]. CGColor; // black self. layer. shadowOpacity = 0.33; // shadow opacity self. layer. shadowOffset = CGSizeMake (0, 1.5); // The Shadow offset self. layer. shadowRadius = 4.0; // shadowRadius self. layer. shouldRasterize = YES; // rounded corner cache self. layer. rasterizationScale = [UIScreen mainScreen]. scale; // improve smoothness // rounded self. layer. cornerRadius = 10.0f ;}

Instructions:
Context switching

Context switching, whether in the GPU rendering process or the familiar process switching, is a very time-consuming operation. First, I want to save the current screen rendering environment, switch to a new painting environment, apply for drawing resources, initialize the environment, and then start a painting. After the painting is complete, destroy the painting environment, if you need to switch to On-Screen Rendering or start a new operation before repeated off-Screen Rendering. Describes a mask rendering operation.

self.layer.shouldRasterize = YES;  self.layer.rasterizationScale = [UIScreen mainScreen].scale;

In most cases, the number of frames saved is more than 55 per second. ShouldRasterize = YES will cache the rendering content of the view, and the cache will be displayed directly next time you draw it. Of course, the view content will not change.

In addition to the dead, it is better to generate a rounded image in advance and cache the image. The pre-processed rounded corner image can be processed in the background, cached after processing, and displayed in the main thread. This avoids unnecessary off-screen rendering.

In addition, there is also a method to cover a hollow circular image on the image to achieve the circular Avatar effect, which is also an extremely efficient method. The disadvantage is that the background of the view is required, and the effect of the monochrome background is the most ideal.

Summary

The implementation of the rounded corner cornerRadius is much more efficient than the mask.

Rasterize greatly reduces GPU work in most cases. In the case of space, the cache can always help you in most cases, isn't it?

Background preprocessing can also be very easy to help you.

Related Article

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.