利用mask layer 勾View

  1. #define SCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width  
  2. #define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height  
  3.   
  4. - (void)addMask{  
  5.     UIButton * _maskButton = [[UIButton alloc] init];  
  6.     [_maskButton setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];  
  7.     [_maskButton setBackgroundColor:[UIColor colorWithWhite:0 alpha:0.7]];  
  8.     [self.view addSubview:_maskButton];  

 

  1.       //把下面代码加入到view的-drawRect'中便可以实现
  2.     //create path  
  3.     UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];  
  4.       
  5.     // MARK: circlePath  
  6.     [path appendPath:[UIBezierPath bezierPathWithArcCenter:CGPointMake(SCREEN_WIDTH / 2, 200) radius:100 startAngle:0 endAngle:2*M_PI clockwise:NO]];  
  7.       
  8.     // MARK: roundRectanglePath  
  9.     [path appendPath:[[UIBezierPath bezierPathWithRoundedRect:CGRectMake(20, 400, SCREEN_WIDTH - 200100) cornerRadius:15] bezierPathByReversingPath]];  
  10.       
  11.     CAShapeLayer *shapeLayer = [CAShapeLayer layer];  
  12.       
  13.     shapeLayer.path = path.CGPath;  
  14.       
  15.     [_maskButton.layer setMask:shapeLayer];  
  16. }
posted @ 2016-04-21 11:31  橘子与布丁  阅读(170)  评论(0编辑  收藏  举报