質問

Shadow effect

Does any one know how to achieve the shadow effect with no gradient? Like the screenshot show below

Another concern is the sequence of subviews, i.e the view in front may hide the effect of the view in behind. How to overcome this?

役に立ちましたか?

解決

For the first problem you can change the shadowRadius of the shadow, for example:

//You must include QuartzCore framework (#import <QuartzCore/QuartzCore.h>)
view.layer.cornerRadius = 5;
view.layer.shadowRadius = 0; //The shadow should be rendered as a solid shape
view.layer.shadowOffset = CGSizeMake(0, 2);
view.layer.shadowOpacity = 0.5;
view.layer.shadowColor = [UIColor blackColor].CGColor;

UIBezierPath *path = [UIBezierPath bezierPathWithRect:view.bounds];
view.layer.shadowPath = path.CGPath; //This is very important!

Remember to always set the shadowPath! If you don't the performance of rendering the shadow will decrease a lot.

For the second problem, sorry but I don't think there's a way to let the shadow of an object appear over another view that is over the original one.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top