设为首页 加入收藏

TOP

iOS 学习 - 16.绘制虚线
2017-10-13 10:23:37 】 浏览:2716
Tags:iOS 学习 16. 绘制
//绘制虚线
-(void)set{ UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 100, 320, 20)]; [self.view addSubview:imageView]; //创建一个基于位图的上下文,大小为 imageView 的大小
 UIGraphicsBeginImageContext(imageView.frame.size); //绘图位置,相对画布顶点而言
    [imageView.image drawInRect:CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height)]; //设置端点的格式
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapSquare);//绘制方形端点 //{10,10} 表示先绘制 10 个点,再跳过 10 个点,重复。。。 //{10,20,10} 表示先绘制 10 个,跳过 20 个,绘制 10 个点,跳过 10 个,绘制 20 个,重复。。相应的 count 要等于lengths 的个数
    CGFloat lengths[] = {10,10}; CGContextRef line = UIGraphicsGetCurrentContext(); //虚线的颜色
 CGContextSetStrokeColorWithColor(line, [UIColor redColor].CGColor); //phase 表示绘制的时候跳过多少个点
    CGContextSetLineDash(line, 0, lengths, 2); //绘制的起点
    CGContextMoveToPoint(line, 0.0, 20); //终点
    CGContextAddLineToPoint(line, 310, 20); //画线
 CGContextStrokePath(line); imageView.image = UIGraphicsGetImageFromCurrentImageContext(); }

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇RDVTabBarController的基本使用 .. 下一篇【转】iOS学习之Storyboard中的UI..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目