为什么给任何图层添加阴影都太重了?使用 QuartzCore [英] Why add shadow to any layer is too heavy? Using QuartzCore

查看:88
本文介绍了为什么给任何图层添加阴影都太重了?使用 QuartzCore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么给任何图层添加阴影都太重了?

Why add shadow to any layer is too heavy?

我尝试向 UIView 添加阴影,但仅在此屏幕上它非常沉重.

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

怎么这么重?我找到的唯一解决方案是在 PNG 中添加阴影图像进行模拟,比使用 QuartzCore 创建阴影更轻.

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?

推荐答案

使用以下函数为任何控件(如按钮、标签、文本字段或视图)提供阴影,只需将该控件传递给此函数

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 .......

这篇关于为什么给任何图层添加阴影都太重了?使用 QuartzCore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆