Why add shadow to any layer is too heavy? Using Qu

2019-09-08 11:49发布

问题:

Why add shadow to any layer is too heavy?

I tried to add a shadow to my UIView and it was VERY heavy on this screen only.

Why is it so heavy? The only solution I find is to add a shadow image in PNG to simulate, is lighter than create a shadow using QuartzCore.

Is there any solution lighter for this?

回答1:

use following function to give shadow to any control like, button, label, textfield or view just pass that control to this function

    - (void)setShadowOnView:(UIView)aView
    {
        CALayer *layer = aView.layer;
        layer.masksToBounds = NO;
        layer.shadowColor = [[UIColor blackColor] CGColor];//change is to set color of shadow
        layer.shadowOpacity = 1.f;//change is to set alpha of shadow
        layer.shadowOffset = CGSizeMake(-2.5f, 0.f);//change is to set size of shadow
        layer.shadowRadius = 5.f;//change is to set radios of shadow
        layer.shadowPath = [[UIBezierPath bezierPathWithRect:aView.bounds] CGPath];
    }

try to set properties as you like and as per your requirement..

Enjoy coding .......