UI设计师有时候希望我们的产品比较酷。

阴影是他们喜欢的效果之一。

怎么设置阴影呢?

1、设置一个四边都相同的阴影

   UIImageView *testImgView = [[UIImageView alloc]initWithFrame:CGRectMake(, , , )];

    [testImgView setBackgroundColor:[UIColor yellowColor]];

    // 阴影颜色
testImgView.layer.shadowColor = [UIColor blackColor].CGColor;
// 阴影偏移,默认(0, -3)
testImgView.layer.shadowOffset = CGSizeMake(,);
// 阴影透明度,默认0
testImgView.layer.shadowOpacity = 0.5;
// 阴影半径,默认3
testImgView.layer.shadowRadius = ; [self.view addSubview:testImgView];

效果如图:

2、设置单边阴影

//单边阴影

    UILabel *testLabel = [[UILabel alloc]initWithFrame:CGRectMake(, , , )];

    [testLabel setBackgroundColor:[UIColor yellowColor]];

    // 阴影颜色
testLabel.layer.shadowColor = [UIColor blackColor].CGColor; // 阴影偏移,默认(0, -3)
testLabel.layer.shadowOffset = CGSizeMake(,); // 阴影透明度,默认0
testLabel.layer.shadowOpacity = 0.5;
// 阴影半径,默认3
testLabel.layer.shadowRadius = ; // 单边阴影 顶边
float shadowPathWidth = testLabel.layer.shadowRadius; CGRect shadowRect = CGRectMake(-shadowPathWidth/2.0, -shadowPathWidth/2.0, testLabel.bounds.size.width+shadowPathWidth, shadowPathWidth); UIBezierPath *path = [UIBezierPath bezierPathWithRect:shadowRect];
testLabel.layer.shadowPath = path.CGPath; [self.view addSubview:testLabel];

效果如下:

3、和阴影相关的属性

/** Shadow properties. **/

/* The color of the shadow. Defaults to opaque black. Colors created
* from patterns are currently NOT supported. Animatable. */ @property(nullable) CGColorRef shadowColor; /* The opacity of the shadow. Defaults to 0. Specifying a value outside the
* [0,1] range will give undefined results. Animatable. */ @property float shadowOpacity; /* The shadow offset. Defaults to (0, -3). Animatable. */ @property CGSize shadowOffset; /* The blur radius used to create the shadow. Defaults to 3. Animatable. */ @property CGFloat shadowRadius; /* When non-null this path defines the outline used to construct the
* layer's shadow instead of using the layer's composited alpha
* channel. The path is rendered using the non-zero winding rule.
* Specifying the path explicitly using this property will usually
* improve rendering performance, as will sharing the same path
* reference across multiple layers. Upon assignment the path is copied.
* Defaults to null. Animatable. */ @property(nullable) CGPathRef shadowPath;

UIView设置阴影的更多相关文章

  1. iPhone之为UIView设置阴影(CALayer的shadowColor,shadowOffset,shadowOpacity,shadowRadius,shadowPath属性)

    效果图: 以下代码实现: 第一个图片的代码 //加阴影--任海丽编辑 _imageView.layer.shadowColor = [UIColor blackColor].CGColor;//sha ...

  2. UIView 设置阴影(属性说明)

    以下代码实现: 第一个图片的代码 //加阴影--任海丽编辑 _imageView.layer.shadowColor = [UIColor blackColor].CGColor;//shadowCo ...

  3. UIView设置阴影无效的原因之一

    本想在底部的按钮设置个阴影, 代码如下: self.layer.shadowColor = [UIColor blackColor].CGColor; self.layer.shadowOffset ...

  4. swift 设置阴影和圆角

    1.正常view设置阴影 func setShadow(view:UIView,sColor:UIColor,offset:CGSize, opacity:Float,radius:CGFloat) ...

  5. div四个边框分别设置阴影样式

    对于div边框的阴影一直没有很好地理解,也一直不明白怎么给四个边框分别设置阴影.昨天项目中碰到了这个问题,就认真想了一下,在此总结一二. 首先,还是从官方解释说起. 网上的解释通常都是什么水平阴影长度 ...

  6. iOS UIView设置圆角

    UIView设置圆角 1.比较简单的情况,UIView四个角都是圆角: UIView *aView = [[UIView alloc] init]; aView.frame = CGRectMake( ...

  7. UIView设置背景渐变色

    UIView设置背景渐变色 // Allocate bitmap context CGContextRef bitmapContext = CGBitmapContextCreate(NULL, , ...

  8. 使文字在div中水平和垂直居中的的css样式为,四个边分别设置阴影样式

    text-align:center; /*水平居中*/ line-height: 20px; /*行距设为与div高度一致*/ HTML元素 <div>水平垂直居中</div> ...

  9. IOS UIView圆角,阴影,边框,渐增光泽

    圆角 sampleView.layer.cornerRadius = 2.5; // 圓角的弧度sampleView.layer.masksToBounds = YES; 阴影 sampleView. ...

随机推荐

  1. 松软科技Web课堂:JavaScript While 循环

    只要条件为 true,循环能够一直执行代码块. While 循环 while 循环会一直循环代码块,只要指定的条件为 true. 语法 while (条件) { 要执行的代码块 } 实例 在下面的例子 ...

  2. everspin自旋转矩MRAM技术

    MRAM的主体结构由三层结构的MTJ构成:自由层(free layer),固定层和氧化层.自由层与固定层的材料分别是CoFeB和MgO.MRAM 是一种非易失性的磁性随机存储器.它拥有静态随机存储器( ...

  3. Cross-Site Scripting:DOM 跨站点脚本:DOM

  4. Consul初探-服务注册和发现

    前言 经过上一篇的学习,现在已经来到了服务注册发现环节:Consul 的核心功能就是服务注册和发现,Consul 客户端通过将自己注册到 Consul 服务器集群,然后等待调用方去发现服务,实现代理转 ...

  5. Linux逻辑卷的创建

    什么是LVM? LVM(逻辑卷管理器):是Linux环境下对磁盘分区进行管理的一种机制.主要作用是动态分配磁盘分区及调整磁盘分区大小,并且可以让多个分区或者物理硬盘作为一个逻辑卷(相当于一个逻辑硬盘) ...

  6. vue中使用element组件时事件想要传递其他参数的问题

    在使用element的上传组件时在一下几个钩子中传递其他参数 图中是文件上传时的几个钩子,参数为文件或文件列表或者其他参数,但是现在我想在原有参数上传递其他参数.比如我想在on-success的钩子中 ...

  7. JDK新特性关于流操作部分

    // array 工具类 可以用来快捷的将数组转化为list List<String> strings = Arrays.asList("zhongguo", &quo ...

  8. vue-better-scroll实现移动端下拉加载组件

    1.下载安装better-scroll npm i -S better-scroll 1.1安装完成之后,打开pacaage.json文件查看,是否有(better-scroll) "dep ...

  9. 内存取证工具-volatility、foremost

    内存取证 1. 内存取证工具volatility 猜测dump文件的profile值 root@kali:~/CTF# volatility -f mem.vmem imageinfo Volatil ...

  10. 微店APP协议简要分析

    1.通过抓包软件charles进行抓包,点击微信收款后,抓包内容都是加密处理过  2.加载分析定位这些字段的加密函数. WDTNThorParameterProcessor HTTPBody:task ...