000-CALayer阴影

1、通过设置CALayer来给视图控件添加阴影


#import "ViewController.h"

@interface ViewController ()

/**
 *  测试View
 */
@property (nonatomic, strong) UIView *testView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.testView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    self.testView.backgroundColor = [UIColor orangeColor];
    
    //0、圆角
    self.testView.layer.cornerRadius = 5;
    //1、设置图层阴影的范围
    self.testView.layer.shadowRadius = 10;
    //2、设置图层阴影的偏移量
    self.testView.layer.shadowOffset = CGSizeMake(10, -10);
    //3、设置图层阴影的颜色
    self.testView.layer.shadowColor = [UIColor blackColor].CGColor;
    //4、设置图层阴影的透明度
    self.testView.layer.shadowOpacity = 0.7;
    //5、添加边框宽度
    self.testView.layer.borderWidth = 3.0;
    //6、添加边框颜色
    self.testView.layer.borderColor = [UIColor blackColor].CGColor;
    
    [self.view addSubview:self.testView];
}

2、效果如下:

QQ20161221-1@2x.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 8,578评论 6 30
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌。在这里你可以看...
    F麦子阅读 5,147评论 5 13
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,663评论 25 708
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,259评论 4 61
  • 运动与书籍不可辜负,生活不因年龄而设限 摄于2017.8.29——小柳
    柳如柳阅读 260评论 0 0