layer图层常见属性

把layer常见图层属性总结了一下^-^欢迎大家讨论~~~~来吧 ,代码属性

#import "CZViewController.h"

@interface CZViewController ()

@property (nonatomic, strong) UIView *myView;
@property (nonatomic, strong) UIImageView *imageView; @end @implementation CZViewController - (UIImageView *)imageView
{
if (_imageView == nil) {
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(110, 100, 100, 100)];
_imageView.image = [UIImage imageNamed:@"头像1"]; _imageView.backgroundColor = [UIColor redColor]; [self.view addSubview:_imageView];
}
return _imageView;
} - (UIView *)myView
{
if (_myView == nil) {
_myView = [[UIView alloc] initWithFrame:CGRectMake(110, 100, 100, 100)];
_myView.backgroundColor = [UIColor redColor]; [self.view addSubview:_myView];
}
return _myView;
} - (void)viewDidLoad
{
[super viewDidLoad]; self.view.backgroundColor = [UIColor lightGrayColor]; [self imageView]; // 1. 阴影效果,在CA框架中不能直接使用UIKit的数据类型
//阴影颜色
self.imageView.layer.shadowColor = [UIColor yellowColor].CGColor;
//阴影偏移点
// self.myView.layer.shadowOffset = CGSizeMake(-10, 10);
//阴影半径
self.imageView.layer.shadowRadius = 10.0;
// 图层中的Opacity相当于view的alpha属性
self.imageView.layer.shadowOpacity = 1.0; // 2. 圆角半径
// 类似于clip,使用masksToBounds阴影效果无效
self.imageView.layer.masksToBounds = YES;
//图层的圆角半径
self.imageView.layer.cornerRadius = 50.0; // 3. 边框 颜色
self.imageView.layer.borderColor = [UIColor whiteColor].CGColor;
//边线宽度
self.imageView.layer.borderWidth = 5.0;
} - (void)viewLayerDemo
{
// 1. 阴影效果,在CA框架中不能直接使用UIKit的数据类型
self.myView.layer.shadowColor = [UIColor yellowColor].CGColor;
// self.myView.layer.shadowOffset = CGSizeMake(-10, 10);
self.myView.layer.shadowRadius = 10.0;
// 图层中的Opacity相当于view的alpha属性
self.myView.layer.shadowOpacity = 1.0; // 2. 圆角半径
self.myView.layer.cornerRadius = 50.0; // 3. 边框
self.myView.layer.borderColor = [UIColor whiteColor].CGColor;
self.myView.layer.borderWidth = 5.0;
} @end // 设置圆角半径
_imageView.layer.cornerRadius = 75;
// 阴影半径
// _imageView.layer.shadowRadius = 75;
// 阴影颜色
_imageView.layer.shadowColor = [UIColor yellowColor].CGColor;
// 阴影偏移位
_imageView.layer.shadowOffset = CGSizeMake( -10, 10);
// 阴影不透明度(0~1)默认是0
_imageView.layer.shadowOpacity = 1;
// 超出主层时添加蒙板遮盖
_imageView.layer.masksToBounds = YES;
// 裁剪超出边界的内容
// _imageView.clipsToBounds = YES;
// 边框线宽
_imageView.layer.borderWidth = 2;
// 边框颜色
_imageView.layer.borderColor = [UIColor blueColor].CGColor;
// CGRect imageVF = CGRectMake(-5, -2, _imageView.bounds.size.width + 10, _imageView.bounds.size.height + 10);
// 阴影(路径)或形状 系统会高点
// _imageView.layer.shadowPath = CGPathCreateWithRect(imageVF, NULL);
上一篇:linux内核Makefile整体分析


下一篇:开源的Delphi性能调试工具