简体   繁体   中英

How to create UIView with custom shape propely?

I have to create UIView with custom shape, such as triangular, half-rect, etc. I used to crop special image to that form and set as a background of my view. Although it is a popular solution, I am not sure whether it is the most efficient one in terms of sustainability.

On the other hand, I found useful way of solving this problem with CAShapeLayer()

Could you please provide pros and cons of both approaches?

CAShapeLayer all the way!

With little effort you can achieve the same result with less memory (RAM) and less maintenance time (if you want to make the triangle thicker for example, you'll need a new image however a small change in code and you have it!). Moreover your app size will be relatively smaller and you don't have to worry about the resolution like the images.

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM