Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在UIView中的两个图像视图之间绘制一条线_Iphone_Objective C_Xcode - Fatal编程技术网

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

Iphone 在UIView中的两个图像视图之间绘制一条线,iphone,objective-c,xcode,Iphone,Objective C,Xcode,我想在UIView中的图像视图(如链接图像…)之间画一条线。我用过 CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor); CGContextSetLineWidth(context, 2.0); CGContextMoveToPoint(context, 0,0); //start at t

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

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);
但在这里,我的上下文是空的。我不知道是否需要导入任何框架或导入任何标题。如有任何建议或样品,将不胜感激

提前谢谢

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();

…而“yourImageView”是一个图像视图,您将在其中画线。我建议您在每个上部图像视图的最底部画一条线,这是一个选项。

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


您是在哪里编写此代码的?您必须导入Quartz框架并将其写入标题:
#import
,但如果您没有导入此代码,则可能会出现编译器错误,因此这可能不是问题所在。我建议您阅读我在ViewDidLoad中编写的这篇文章。。对我来说什么都不管用。。我已经在ViewDidload中编写了这段代码。。我只需要在两个图像视图之间画一条简单的线。。我无法发布图像..伙计,这段代码非常有用:在屏幕上显示ImageView后,将其中一个ImageView用作“yourImageView”,然后只执行一次代码。谢谢你的支持,伙计。。这是我的最终代码。。我对UIView和drawRect方法进行了子类化,如下所示。。CGContextRef context=UIGraphicsGetCurrentContext();//使用白色笔划颜色CGContextSetRGBStrokeColor(上下文,1.0,1.0,1.0,1.0)绘制线条;//以2.0的笔划宽度绘制它们,使它们更可见。CGContextSetLineWidth(上下文,5.0);//从左到右绘制一条直线CGContextMoveToPoint(上下文,90,90.0);CGContextAddLineToPoint(上下文,120.0、150.0);CGContextStrokePath(上下文)@user1402675:这取决于你。谢谢你的评论。
UILabel *seperator=[[UILabel alloc]initWithFrame:CGRectMake(0, 53, 233, 1)];
seperator.backgroundColor=[UIColor redColor];

[loginView addSubview:seperator];
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);