iOS开发中CALayer使用的基本教程

2020-01-14 17:52:10于丽

  新建一个项目,在storyboard中添加一个view.

iOS开发中CALayer使用的基本教程

1.通过layer设置边框的宽度和颜色

复制代码
#import "YYViewController.h"

 

@interface YYViewController ()
@property (weak, nonatomic) IBOutlet UIView *customView;

@end


复制代码
@implementation YYViewController

 

- (void)viewDidLoad
{
    [super viewDidLoad];
    //设置边框的宽度为20
    self.customView.layer.borderWidth=20;
    //设置边框的颜色
    self.customView.layer.borderColor=[UIColor greenColor].CGColor;
}

@end


 

iOS开发中CALayer使用的基本教程

2.通过layer设置边框为圆角

复制代码
//设置layer的圆角
self.customView.layer.cornerRadius=20;

 

iOS开发中CALayer使用的基本教程

3.在layer上添加一张图片 

复制代码
#import "YYViewController.h"

 

@interface YYViewController ()
@property (weak, nonatomic) IBOutlet UIView *customView;