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

时间:2012-07-23 07:39:58

标签: iphone objective-c xcode

我想在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);

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

提前致谢。

3 个答案:

答案 0 :(得分:1)

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

UILabel *seperator=[[UILabel alloc]initWithFrame:CGRectMake(0, 53, 233, 1)];
seperator.backgroundColor=[UIColor redColor];

[loginView addSubview:seperator];

答案 1 :(得分:0)

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”是一个用于绘制线条的imageview。我建议你在每个上面的imageview画线,在最底部,这是一个选项。

答案 2 :(得分:0)

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); 
相关问题