Layer基本操作

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.layer.backgroundColor = [UIColor redColor].CGColor;
    self.view.backgroundColor = [UIColor whiteColor];
    CALayer *layer = [CALayer layer];
    layer.anchorPoint = CGPointMake(0, 0);
    layer.bounds = CGRectMake(0, 0, 200, 200);
    layer.position = CGPointMake([UIScreen mainScreen].bounds.size.width/2, 200);
    layer.backgroundColor = [UIColor greenColor].CGColor;
    [self.view.layer addSublayer:layer];
    
    layer.transform = CATransform3DMakeRotation(M_PI_4, 0, 0, 1);//三维旋转,参数1设置角度,后面3个参数设置旋转轴
    
    layer.cornerRadius = 50;
    
    UIImage *image = [UIImage imageNamed:@"circle.png"];
    layer.contents = (__bridge id)(image.CGImage);
    
    layer.borderWidth = 10;
    layer.borderColor = [UIColor blueColor].CGColor;
    
    layer.shadowOpacity = 0.5;//设置阴影的透明度,一定要设置,默认为0
    layer.shadowOffset = CGSizeMake(10, 3);
    layer.shadowColor = [UIColor blackColor].CGColor;
    
    CALayer *layer1 = [CALayer layer];
    layer1.anchorPoint = CGPointMake(0.5, 0.5);
    layer1.frame = CGRectMake(50, 50, 100, 100);
    layer1.backgroundColor = [UIColor cyanColor].CGColor;
    [layer addSublayer:layer1];
    
    layer1.transform = CATransform3DMakeRotation(-M_PI_4, 0, 0, 1);
    layer1.cornerRadius = 20;
    
    CALayer *layer2 = [CALayer layer];
    layer2.backgroundColor = [UIColor orangeColor].CGColor;
    layer2.frame = CGRectMake(0, 0, 100, 100);
    [layer addSublayer:layer2];
    
    layer.masksToBounds = YES;//裁切超出范围的图像,同时会裁切阴影
    
    
    // Do any additional setup after loading the view, typically from a nib.
}

你可能感兴趣的:(iOS,UI专辑,uiimage,三维,imageview,interface,object)