#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = CGRectMake(0, 100, self.view.bounds.size.width, 100);
[self.view.layer addSublayer:gradientLayer];
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(1, 0);
NSArray *colors = @[(__bridge id)[UIColor redColor].CGColor,(__bridge id)[UIColor greenColor].CGColor];
gradientLayer.colors = colors;
gradientLayer.locations = @[@0,@1];
CATextLayer *textLayer = [CATextLayer layer];
textLayer.string = @"这是一个渐变";
textLayer.frame = CGRectMake(0, 0, self.view.bounds.size.width, 100);
[gradientLayer addSublayer:textLayer];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.backgroundColor = [UIColor blueColor].CGColor;
shapeLayer.frame = CGRectMake(100, 200, 100, 100);
[self.view.layer addSublayer:shapeLayer];
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddEllipseInRect(path, NULL, CGRectMake(0, 0, 50, 50));
shapeLayer.path = path;
shapeLayer.fillColor = [UIColor yellowColor].CGColor;
CGPathRelease(path);
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = CGRectMake(0, 100, self.view.bounds.size.width, 100);
[self.view.layer addSublayer:gradientLayer];
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(1, 0);
NSArray *colors = @[(__bridge id)[UIColor redColor].CGColor,(__bridge id)[UIColor greenColor].CGColor];
gradientLayer.colors = colors;
gradientLayer.locations = @[@0,@1];
CATextLayer *textLayer = [CATextLayer layer];
textLayer.string = @"这是一个渐变";
textLayer.frame = CGRectMake(0, 0, self.view.bounds.size.width, 100);
[gradientLayer addSublayer:textLayer];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.backgroundColor = [UIColor blueColor].CGColor;
shapeLayer.frame = CGRectMake(100, 200, 100, 100);
[self.view.layer addSublayer:shapeLayer];
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddEllipseInRect(path, NULL, CGRectMake(0, 0, 50, 50));
shapeLayer.path = path;
shapeLayer.fillColor = [UIColor yellowColor].CGColor;
CGPathRelease(path);
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end