1

似乎对此有很多想法,还有一些问题。然而,他们中的一些人说某些代码有效。例如:

[self.layer setShadowOffset:CGSizeMake(1, 3)];
[self.layer setShadowOpacity:0.9];
[self.layer setShadowRadius:3.0f];
[self.layer setShouldRasterize:YES];

[self.layer setCornerRadius:12.0f];

[self.layer setShadowPath:[[UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:12.0f] CGPath]];

应同时应用 12.0f 角半径和阴影。但它不起作用。当我使用这段代码时,我得到了阴影,但没有圆角半径。

据我所知,这是因为我需要将 clipsToBounds 设置为 YES。但是,这反过来又否定了阴影。

我做错了什么还是上面的代码不起作用?

此外,人们说克服这个问题的好方法是创建一个单独的阴影层,然后添加它。

但是我将如何在 UIView 的 drawRect: 中做到这一点?- 示例代码会很棒!

谢谢!

4

1 回答 1

0

Your code looks good i have tried your code and it works fine with me.

make sure rect used in [[UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:12.0f] CGPath]] is correct and if you are using black background then you can not see shadow.

i have tried this in my code. Here is the working code.......

[self.EnterQtyView.layer setShadowOffset:CGSizeMake(1, 5)];
[self.EnterQtyView.layer setShadowOpacity:1.0];
[self.EnterQtyView.layer setShadowRadius:5.0f];
[self.EnterQtyView.layer setShouldRasterize:YES];
[self.EnterQtyView.layer setCornerRadius:12.0f];
[self.EnterQtyView.layer setShadowPath:[[UIBezierPath bezierPathWithRoundedRect:self.EnterQtyView.frame cornerRadius:12.0f] CGPath]];

Hope this will help you.................

于 2013-03-19T09:34:47.560 回答