首页 > 其他 > 详细

利用mask layer 勾View

时间:2016-04-21 13:25:48      阅读:313      评论:0      收藏:0      [点我收藏+]
  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. }

利用mask layer 勾View

原文:http://www.cnblogs.com/xiguapijiamuguanaicha/p/5416264.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!