首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在UIView中两个图像视图之间绘制一条线

在UIView中两个图像视图之间绘制一条线
EN

Stack Overflow用户
提问于 2012-07-23 15:39:58
回答 3查看 1K关注 0票数 0

我想在图像视图之间画一条线(比如链接图像..)在UIView中。我用过

代码语言:javascript
复制
CGContextRef context    = UIGraphicsGetCurrentContext();

CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);

CGContextSetLineWidth(context, 2.0);

CGContextMoveToPoint(context, 0,0); //start at this point

CGContextAddLineToPoint(context, 20, 20); //draw to this point

CGContextStrokePath(context);

但是在这里,我的上下文是空的。我不知道我是否必须导入任何框架或导入任何头文件。任何建议或样品将不胜感激。

提前谢谢。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-08-30 01:03:44

代码语言:javascript
复制
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
 CGContextSetLineWidth(context, 5.0); 
CGContextMoveToPoint(context, 90, 90.0); 
CGContextAddLineToPoint(context, 120.0, 150.0);
 CGContextStrokePath(context); 
票数 0
EN

Stack Overflow用户

发布于 2012-07-23 15:54:38

最简单方法是使用高度为1的标签。:)

代码语言:javascript
复制
UILabel *seperator=[[UILabel alloc]initWithFrame:CGRectMake(0, 53, 233, 1)];
seperator.backgroundColor=[UIColor redColor];

[loginView addSubview:seperator];
票数 1
EN

Stack Overflow用户

发布于 2012-07-23 15:52:15

代码语言:javascript
复制
UIGraphicsBeginImageContext(image_signature.image.size);
[yourImageView.image drawInRect:CGRectMake(0, 0, yourImageView.image.size.width, yourImageView.image.size.height)]; 
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 2.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), 0, 0);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), 20, 20);
CGContextStrokePath(UIGraphicsGetCurrentContext());
[yourImageView setImage:UIGraphicsGetImageFromCurrentImageContext()];
UIGraphicsEndImageContext();

...and "yourImageView“是一个图像视图,您将在其中绘制直线。我建议你在每个上方的图像视图上画一条线,在最底部,这是一个选项。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11608234

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档