代码:

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@end

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(, , , )]; [self.view addSubview:view]; //添加View的阴影
[self addShadowWithView:view];
//[self addShadowWithView2:view];
} //添加View的阴影
- (void)addShadowWithView:(UIView *)view{ view.layer.shadowColor = [UIColor blackColor].CGColor;//shadowColor阴影颜色,默认为黑色
view.layer.shadowOffset = CGSizeMake(, );
view.layer.shadowOpacity = 1.0;
view.layer.shadowRadius = ; //路径阴影
UIBezierPath *path = [UIBezierPath bezierPath]; float width = view.bounds.size.width;
float height = view.bounds.size.height;
float x = view.bounds.origin.x;
float y = view.bounds.origin.y; CGPoint topLeft = CGPointMake(x, y);
CGPoint topMiddle = CGPointMake(x + (width/), y);
CGPoint topRight = CGPointMake(x + width, y); CGPoint rightMiddle = CGPointMake(x + width, y + (height/)); CGPoint bottomRight = CGPointMake(x+width, y+height);
CGPoint bottomMiddle = CGPointMake(x + (width/), y + height);
CGPoint bottomLeft = CGPointMake(x, y + height); CGPoint leftMiddle = CGPointMake(x, y + (height/)); [path moveToPoint:topLeft];
//添加四个二元曲线
[path addQuadCurveToPoint:topRight controlPoint:topMiddle];
[path addQuadCurveToPoint:bottomRight controlPoint:rightMiddle];
[path addQuadCurveToPoint:bottomLeft controlPoint:bottomMiddle];
[path addQuadCurveToPoint:topLeft controlPoint:leftMiddle]; view.layer.shadowPath = path.CGPath;
} //添加View的阴影2
- (void)addShadowWithView2:(UIView *)view{ //使用这种办法来设置投影,必须添加背景颜色或者边框颜色否则是无法显示的
view.layer.borderColor = [UIColor blueColor].CGColor;
view.layer.borderWidth = 1.0; view.layer.shadowColor = [UIColor blackColor].CGColor;
view.layer.shadowOffset = CGSizeMake(, );
view.layer.shadowOpacity = 1.0;
view.layer.shadowRadius = ; } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

实例代码:

Demo下载

参考链接:

http://blog.csdn.net/rhljiayou/article/details/10178723

最新文章

  1. poj 1651 Multiplication Puzzle
  2. 报错:Failed to instantiate the default view controller for UIMainStoryboardFile &#39;MainStoryboard&#39; - perhaps the designated entry point is not set?
  3. SQLServer2005删除log文件和清空日志的方案
  4. sql xpath 查找包含
  5. hdu 3037 Saving Beans
  6. Linux系统(将web应用部署到tomcat服务器上)
  7. 获取WebView加载HTML时网页中的内容
  8. bzoj4005[JLOI2015]骗我呢
  9. PCB打样镀层问题
  10. Android开发匹配字符笔记
  11. [LeetCode234]Palindrome Linked List
  12. EasyUI项目驱动学习
  13. Android学习-应用程序管理
  14. Python网络数据采集2-wikipedia
  15. 【一天一道LeetCode】#202. Happy Number
  16. JavaScript 基础(三) - Date对象,RegExp对象,Math对象,Window 对象,History 对象,Location 对象,DOM 节点
  17. UVA806-Spatial Structures(四分树)
  18. HikariCP 脑火Failed to obtain JDBC Connection: You need to run the CLI build and you need target/classes in your classpath to run.
  19. 【Unity】11.7 布料
  20. Redis安装系统服务1073错误

热门文章

  1. STM32F103RCT6移植到STM32F103C8T6注意事项
  2. SecureCRT的Home+End+Del键映射
  3. The Princess and the Pea,摘自iOS应用Snow White and more stories
  4. centos6安装nginx最详细步骤
  5. linux c编程:系统数据文件和信息
  6. LigerUI隐藏列
  7. Oracle视图传递参数
  8. Spark0.9.0机器学习包MLlib-Classification代码阅读
  9. ICCV 2015 B-CNN细粒度分类
  10. LeetCode:贪婪算法