0

I`m developing iPhone app, where i using next code to round two corners of my layer :

CAShapeLayer *backgroundMaskLayer = [CAShapeLayer layer];
UIBezierPath *backgroungMaskPath = [UIBezierPath
                                    bezierPathWithRoundedRect:self.layer.bounds
                                    byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
                                    cornerRadii:CGSizeMake(10.0, 10.0)];

self.clipsToBounds = NO;
backgroundMaskLayer.frame = self.layer.bounds;
backgroundMaskLayer.path = backgroungMaskPath.CGPath;
backgroundMaskLayer.lineWidth = 2.0;
backgroundMaskLayer.strokeColor = [UIColor whiteColor].CGColor;
backgroundMaskLayer.fillColor = [UIColor whiteColor].CGColor;

[self.inputBackView.layer addSublayer:backgroundMaskLayer];

But circled layer doesn`t scale with other layers on different devices.

I`ve tried this:

backgroundMaskLayer.contentsScale = [UIScreen mainScreen].scale;
backgroundMaskLayer.rasterizationScale = [UIScreen mainScreen].scale;
backgroundMaskLayer.shouldRasterize = YES;

and this:

- (void)layoutSubviews {
  mylayer.frame = self.bounds;
  }

Also ive tried to make different combinations of constraints, but im still getting this on iPhone 6 (on iPhone 5, it is pretty enough):

layer does not fit

where blue colour is my layer in xib file, on which I impose my CAShapeLayer * backgroundMaskLayer (white colour).

How can i fix it?

Jagat Dave
  • 1,643
  • 3
  • 23
  • 30
  • Small point: if all you're doing is rounding corners, you can do that on a UIView's layer directly rather than having an extra CALayer instance. – TwoStraws Feb 10 '16 at 09:46

1 Answers1

1

Update your layoutSubviews method as:

- (void)layoutSubviews
{
    [super layoutSubviews];
    UIBezierPath *backgroungMaskPath = [UIBezierPath
                                        bezierPathWithRoundedRect:self.bounds
                                        byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
                                        cornerRadii:CGSizeMake(10.0, 10.0)];
    backgroundMaskLayer.path = backgroungMaskPath.CGPath;

}
Aruna Mudnoor
  • 4,795
  • 14
  • 16