开发者

clipToBounds questions: UIView Vs CALayer

I have a class that takes an NSString as a parameter, uses Core Text to get the siz开发者_C百科e of the text, extract each line and renders the text line with different x offsets to give a skewed effect.

I also apply a shadow when Core Graphics is drawing the lines of text, however this shadow get's clipped by the views frame and clipToBounds does not resolve this.

Question 1. I understand that clipsToBounds = NO will only affect subviews. Does this mean UIViews, or does it apply to sub CALayers too?

Question 2. When I draw the CTLines can I use a different UIView or CALayers context to render, so I can use clipsToBounds properly?


  1. clipsToBounds only applies to sublayers, not layer contents, yes.

  2. You can expand the size of your target layer to encompass the area you need for your shadow, which you can figure out from the shadow’s radius and offset. You can manipulate the bounds property of the layer so that the origin stays at the same place even when the layer has been grown.

For instance, if you start with a (100,100) rectangle and have a 1px shadow with (0,0) offset:

layer.bounds = CGRectMake(-1, -1, 102, 102).
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜