UIView - (shadowColor &shadowOffset & shadowOpacity & shadowRadius)属性
2016-01-13 15:20
387 查看
效果图
以下代码实现:
第一张图片的代码:
以下代码实现:
第一张图片的代码:
_imageView1.layer.shadowColor = [UIColor yellowColor].CGColor;//shadowColor阴影颜色 _imageView1.layer.shadowOffset = CGSizeMake(0,0);//shadowOffset阴影偏移,默认(0, -3),这个跟shadowRadius配合使用 _imageView1.layer.shadowOpacity = 1;//阴影透明度,默认0 _imageView1.layer.shadowRadius = 3;//阴影半径,默认3 //路径阴影 UIBezierPath *path = [UIBezierPath bezierPath]; float width = _imageView1.bounds.size.width; float height = _imageView1.bounds.size.height; float x = _imageView1.bounds.origin.x; float y = _imageView1.bounds.origin.y; float addWH = 10; CGPoint topLeft = _imageView1.bounds.origin; CGPoint topMiddle = CGPointMake(x+(width/2),y-addWH); CGPoint topRight = CGPointMake(x+width,y); CGPoint rightMiddle = CGPointMake(x+width+addWH,y+(height/2)); CGPoint bottomRight = CGPointMake(x+width,y+height); CGPoint bottomMiddle = CGPointMake(x+(width/2),y+height+addWH); CGPoint bottomLeft = CGPointMake(x,y+height); CGPoint leftMiddle = CGPointMake(x-addWH,y+(height/2)); [path moveToPoint:topLeft]; //添加四个二元曲线 [path addQuadCurveToPoint:topRight controlPoint:topMiddle]; [path addQuadCurveToPoint:bottomRight controlPoint:rightMiddle]; [path addQuadCurveToPoint:bottomLeft controlPoint:bottomMiddle]; [path addQuadCurveToPoint:topLeft controlPoint:leftMiddle]; //设置阴影路径 _imageView1.layer.shadowPath = path.CGPath;
相关文章推荐
- CALayer与UIView的关系
- UIView的bounds和frame区别
- uiview
- uiview生命周期
- UIView翻译 (参考)
- iOS 转变UIView到UIImage
- UIView动画
- initWithFrame 和 initWithCoder
- [CS193P] 第六堂課摘要及心得筆記
- UI第一天
- 棋盘
- ios实现button变换颜色并可以放大、缩小、旋转
- uiview contentViewmode
- iphone开发小记 基础知识2
- iphone开发小记 基础知识3
- [笔记]I 群聊天记录2012/03/中
- iPhone开发进阶(2) --- iPhone应用程序/项目的构成
- 视图弹出后放大又缩小的动画实现、类似于alertView效果
- iPhone SDK开发:自定义UIAlertView
- IOS开发中的UIScreen、UIView、UIWindow和UIViewController