iOS开发画虚线的方法
2018-04-20 16:13
260 查看
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
[shapeLayer setBounds:self.view.bounds];
[shapeLayer setPosition:self.view.center];
[shapeLayer setFillColor:[[UIColor clearColor] CGColor]];
// 设置虚线颜色为blackColor
[shapeLayer setStrokeColor:[[UIColor blackColor] CGColor]];
[shapeLayer setStrokeColor:[[UIColor colorWithRed:223/255.0 green:223/255.0 blue:223/255.0 alpha:1.0f] CGColor]];
// 3.0f设置虚线的宽度
[shapeLayer setLineWidth:1.0f];
[shapeLayer setLineJoin:kCALineJoinRound];
// 3=线的宽度 1=每条线的间距
[shapeLayer setLineDashPattern:
[NSArray arrayWithObjects:[NSNumber numberWithInt:3],
[NSNumber numberWithInt:1],nil]];
// Setup the path
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 0, 89);
CGPathAddLineToPoint(path, NULL, 320,89);
// Setup the path
CGMutablePathRef path1 = CGPathCreateMutable();
// 0,10代表初始坐标的x,y
// 320,10代表初始坐标的x,y
CGPathMoveToPoint(path1, NULL, 0, 100);
CGPathAddLineToPoint(path1, NULL, 320,100);
[shapeLayer setPath:path];
CGPathRelease(path1);
// 可以把self改成任何你想要的UIView, 下图演示就是放到UITableViewCell中的
[[self.view layer] addSublayer:shapeLayer];
转自:http://blog.it985.com/10031.html
[shapeLayer setBounds:self.view.bounds];
[shapeLayer setPosition:self.view.center];
[shapeLayer setFillColor:[[UIColor clearColor] CGColor]];
// 设置虚线颜色为blackColor
[shapeLayer setStrokeColor:[[UIColor blackColor] CGColor]];
[shapeLayer setStrokeColor:[[UIColor colorWithRed:223/255.0 green:223/255.0 blue:223/255.0 alpha:1.0f] CGColor]];
// 3.0f设置虚线的宽度
[shapeLayer setLineWidth:1.0f];
[shapeLayer setLineJoin:kCALineJoinRound];
// 3=线的宽度 1=每条线的间距
[shapeLayer setLineDashPattern:
[NSArray arrayWithObjects:[NSNumber numberWithInt:3],
[NSNumber numberWithInt:1],nil]];
// Setup the path
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 0, 89);
CGPathAddLineToPoint(path, NULL, 320,89);
// Setup the path
CGMutablePathRef path1 = CGPathCreateMutable();
// 0,10代表初始坐标的x,y
// 320,10代表初始坐标的x,y
CGPathMoveToPoint(path1, NULL, 0, 100);
CGPathAddLineToPoint(path1, NULL, 320,100);
[shapeLayer setPath:path];
CGPathRelease(path1);
// 可以把self改成任何你想要的UIView, 下图演示就是放到UITableViewCell中的
[[self.view layer] addSublayer:shapeLayer];
转自:http://blog.it985.com/10031.html
相关文章推荐
- iOS开发画虚线的方法
- IOS开发中,手工要求UITableView 根据新的内容重写画表单的方法
- 打开键盘遮住View的问题解决方法-IOS开发
- IOS开发之Quart绘图方法简介
- ios开发常见错误及解决方法
- 【iOS-Cocos2d游戏开发之十一】使用Box2d物理系统以及在cocos2d框架添加Box2d物理系统lib包的方法
- 【iOS-Cocos2d游戏开发之十一】使用Box2d物理系统以及在cocos2d框架添加Box2d物理系统lib包的方法
- ios 开发 iphone和ipad程序中使用google地图的方法
- iOS开发之回调delegate的方法时判断delegate是否已经被释放
- ios开发笔记-循环调用/执行一个方法
- IOS开发中发送Email的两种方法
- 深度解析IOS开发中编码转换方法
- (iPhone/iPad开发)iOS应用检查更新的最优方法
- ios开发中类方法以及self的注意点
- 【iOS-Cocos2d游戏开发之十一】使用Box2d物理系统以及在cocos2d框架添加Box2d物理系统lib包的方法 推荐
- 【iOS-Cocos2d游戏开发之十一】使用Box2d物理系统以及在cocos2d框架添加Box2d物理系统lib包的方法
- IOS开发中的变量、方法、属性
- 打开键盘遮住View的问题解决方法-IOS开发
- 【iOS-Cocos2d游戏开发之十一】使用Box2d物理系统以及在cocos2d框架添加Box2d物理系统lib包的方法
- [IOS]iphone开发之UIImage应用与内存管理,UIImage加载图像方法