私はCAGradientLayer
自分のイメージで使用しています。これを行うには、次のコードを使用します。
UIImage *image = [UIImage imageNamed:@"perfect.jpg"];
[testImage setImage:image];
CAGradientLayer *myLayer = [CAGradientLayer layer];
myLayer.anchorPoint = CGPointZero;
//starts in bottom left
myLayer.startPoint = CGPointMake(1.0f,1.0f);
//ends in top right
myLayer.endPoint = CGPointMake(1.0f, 0.0f);
UIColor *outerColor = [UIColor colorWithWhite:1.0 alpha:0.0];
UIColor *innerColor = [UIColor colorWithWhite:1.0 alpha:1.0];
//an array of colors that dictatates the gradient(s)
myLayer.colors = @[(id)outerColor.CGColor, (id)outerColor.CGColor, (id)innerColor.CGColor, (id)innerColor.CGColor];
//these are percentage points along the line defined by our startPoint and endPoint and correspond to our colors array. The gradient will shift between the colors between these percentage points.
myLayer.locations = @[@0.0, @0.15, @0.5, @1.0f];
myLayer.bounds = CGRectMake(0, 0, CGRectGetWidth(testImage.bounds), CGRectGetHeight(testImage.bounds));
testImage.layer.mask = myLayer;
[self.view addSubview:testImage];
しかし、私が欲しいのは、放射状グラデーションまたは円形グラデーション効果です。片側だけグラデーションがかかっています。円形のグラデーション レイヤーを作成するにはどうすればよいですか? ありがとう。