I'm developing an iOS application with latest SDK.
I want to add a CALayer inside an UIView and this CALayer will be smaller than the UIView. I want to simulate some kind of margin.
static int const NSLayerX = 0;
static int const NSLayerY = 0;
static int const NSLayerWidth = 60;
static int const NSLayerHeight = 60;
- (void)setBackgroundLayer:(UIColor*)startColor endColor:(UIColor*)endColor cornerRadius:(int)radius
{
backgroundGradientLayer = [CAGradientLayer layer];
backgroundGradientLayer.frame = CGRectMake(NSLayerX, NSLayerY, NSLayerWidth, NSLayerHeight);
backgroundGradientLayer.cornerRadius = radius;
backgroundGradientLayer.colors =
[NSArray arrayWithObjects:(id)[startColor CGColor], (id)[endColor CGColor], nil];
[self.layer insertSublayer:backgroundGradientLayer atIndex:0];
}
But I don't know how to set it centered.
Do I have to change values for NSLayerX and NSLayerY?
Assign frame of the layer as following.
backgroundGradientLayer.frame = CGRectMake(self.frame.size.width/4, self.frame.size.height/4, self.frame.size.width/2, self.frame.size.height/2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With