MyView *myView = [[MyView alloc] initWithFrame:CGRectMake(20., 20., 200., 200.)];
[myView setBackgroundColor:[UIColor colorWithRed:0. green:1. blue:0. alpha:1.]];
CALayer *myLayer = [myView layer];
CGColorRef color = [ViewController getColorFromRed:255 Green:0 Blue:0 Alpha:255];
CALayer *textLayer = [CALayer layer];
textLayer.frame = CGRectMake(0., 0., 100., 100.);
textLayer.backgroundColor = color;
[myLayer addSublayer:textLayer];
//CGAffineTransform transform = CGAffineTransformMakeRotation(45);//45度角旋转
CALayer *imageLayer = [CALayer layer];
imageLayer.frame = CGRectMake(50., 50., 100., 100.);
UIImage *image = [UIImage imageNamed:@"IMG_1001.JPG"];
imageLayer.contents = (id)image.CGImage;
//imageLayer.contentsRect = CGRectMake(20., 20., 20., 20.);
//imageLayer.contentsScale = 2.0;
//[imageLayer setAffineTransform:transform];
imageLayer.contentsGravity = (NSString *)kCAGravityResizeAspect;//设置成按比例缩小, 默认为 kCAGravityResize -> 平铺
[myLayer addSublayer:imageLayer];
//[myLayer insertSublayer:imageLayer below:textLayer];
//CIFilter *filter = [CIFilter filterWithName:@"CIHueAdjust"];
CALayer *maskLayer = [CALayer layer];
maskLayer.backgroundColor = [ViewController getColorFromRed:125 Green:125 Blue:125 Alpha:255];
maskLayer.frame = CGRectMake(20., 20., 50., 50.);
CALayer *boundLayer = [CALayer layer];
boundLayer.frame = CGRectMake(80., 80., 100., 100.);
boundLayer.opaque = NO;
boundLayer.masksToBounds = YES;//是否圆角
boundLayer.cornerRadius = 30.;//圆角的角度
boundLayer.opacity = 0.5;//透明度
boundLayer.borderWidth = 1.0;//边框宽度
boundLayer.borderColor = [ViewController getColorFromRed:125 Green:0 Blue:0 Alpha:255];//边框颜色
boundLayer.backgroundColor = [ViewController getColorFromRed:0 Green:0 Blue:0 Alpha:255];
boundLayer.mask = maskLayer;
[myLayer addSublayer:boundLayer];
[self.view addSubview:myView];
[myView release];
CALayer
最新推荐文章于 2022-12-12 18:30:59 发布