How is the relation between UIView's clipsToBounds and CALayer's masksToBounds?

前端 未结 2 451
悲&欢浪女
悲&欢浪女 2020-11-30 21:01

A UIView has a CALayer. That\'s pretty sure. But both seem to provide something that means the same thing.

If I\'d set clipsToBounds=

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 21:46

    Some one asked what will happen if clipToBounds is set to false and maskToBounds is set to true or it can be better if someone add screenshots

    I stumbled upon the same issue where I wanted to set corner radius and shadow both to the view.

    but it is not possible because as soon as I set masksToBound to YES it removes the shadow but clip the content and if I set it to NO it shows the shadow but does not clip the content.

    I have made the project which explains it better Understanding the ClipToBound And MasksToBound

    I have come to the conclusion that CALayer is not a container but it is simply a class representing a rectangle on the screen with visual content. every drawing done on UIView goes on CALayer which causes the visual content to draw

提交回复
热议问题