BackView *bv = [[BackView alloc] initWithFrame:rect];
  [self.view addSubview:bv];

- (id)initWithFrame:(CGRect)theFrame {
    self = [super initWithFrame:theFrame];
    
    self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.8];
    
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.bounds = [[self layer] bounds];

    CGRect rect = [[self layer] bounds];
    UIBezierPath *outerRectanglePath = [UIBezierPath bezierPathWithRect:rect];
    CGRect rect2 = CGRectMake(rect.size.width/2 - 50, rect.size.height/2- 50, 100, 100);
    UIBezierPath *interRectanglePath = [UIBezierPath bezierPathWithRect:rect2];
    
    [outerRectanglePath appendPath:interRectanglePath];
    maskLayer.path = outerRectanglePath.CGPath;
    maskLayer.position = CGPointMake( rect.size.width / 2.0 , rect.size.height / 2.0 );
    
    maskLayer.fillRule = kCAFillRuleEvenOdd;
//    maskLayer.fillRule = kCAFillRuleNonZero;
    [self layer].mask = maskLayer;
    
    return self;
}

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

© 2024 Falco Tech Blog Suffusion theme by Sayontan Sinha