大佬教程收集整理的这篇文章主要介绍了iphone – 使用CALayer绘制虚线,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
CAShapeLayer *shapeLayer = [CAShapeLayer layer]; CGRect shapeRect = CGRectMake(0.0f,0.0f,200.0f,100.0f); [shapeLayer setBounds:shapeRect]; [shapeLayer setPosition:CGPointMake(self.coreImageView_.frameX,self.coreImageView_.frameBottom - self.coreImageView_.frameHeight/2)]; [shapeLayer setFillColor:[[UIColor clearColor] CGColor]]; [shapeLayer setstrokeColor:[[UIColor whiteColor] CGColor]]; [shapeLayer setLineWidth:2.0f]; [shapeLayer setLineJoin:kCALineJoinRound]; [shapeLayer setLineDashPattern: [NSArray arrayWithObjects:[NSnumber numberWithInt:5],[NSnumber numberWithInt:5],nil]];
CGContextBeginPath(context); CGContextMoveToPoint(context,10.5f,10.5f); CGContextAddLineToPoint(context,20.5f,20.5f); CGContextClosePath(context); CGContextDrawPath(context,kCGPathFillstroke);
对于绘制虚线,您需要使用CAShapeLayer
CAShapeLayer *shapeLayer = [CAShapeLayer layer]; [shapeLayer setBounds:self.bounds]; [shapeLayer setPosition:self.center]; [shapeLayer setFillColor:[[UIColor clearColor] CGColor]]; [shapeLayer setstrokeColor:[[UIColor blackColor] CGColor]]; [shapeLayer setLineWidth:3.0f]; [shapeLayer setLineJoin:kCALineJoinRound]; [shapeLayer setLineDashPattern: [NSArray arrayWithObjects:[NSnumber numberWithInt:10],nil]]; // Setup the path CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path,NULL,10,10); CGPathAddLineToPoint(path,100,100); [shapeLayer setPath:path]; CGPathRelease(path); [[self layer] addSublayer:shapeLayer];
以上是大佬教程为你收集整理的iphone – 使用CALayer绘制虚线全部内容,希望文章能够帮你解决iphone – 使用CALayer绘制虚线所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。