0

I want to draw line between to imageviews (like linking the images..) in UIView. I have used

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

But here, my context is null. I dono whether i have to import any framework or import any headers. Any suggestion or sample will be appreciated.

Thanks in advance.

Garoal
  • 2,364
  • 2
  • 19
  • 31
Sasi
  • 1,666
  • 2
  • 24
  • 44

3 Answers3

1

The very easy way is use label with height 1.:)

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

[loginView addSubview:seperator];
El Developer
  • 3,345
  • 1
  • 21
  • 40
M.B
  • 885
  • 2
  • 15
  • 31
  • Thanks for your supports dude.. Here is my final code.. I have subclassed my UIView and drawRect method as follows.. CGContextRef context = UIGraphicsGetCurrentContext(); // Drawing lines with a white stroke color CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0); // Draw them with a 2.0 stroke width so they are a bit more visible. CGContextSetLineWidth(context, 5.0); // Draw a single line from left to right CGContextMoveToPoint(context, 90, 90.0); CGContextAddLineToPoint(context, 120.0, 150.0); CGContextStrokePath(context); – Sasi Jul 23 '12 at 10:10
  • @user1402675:its depend to you. Thanks for comment. – M.B Jul 23 '12 at 10:15
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();

...and "yourImageView" is an imageview where you will draw the line. I suggest you to draw the line on each upper imageview, at the very bottom, it's an option.

John Smith
  • 2,012
  • 1
  • 21
  • 33
  • Sorry friends.. nothing worked for me.. I have written this code in ViewDidload.. All i need is to dre\aw a simple line between two image views.. I am not able to post the image.. – Sasi Jul 23 '12 at 09:11
  • dude, that code works like a charm: use one of your imageViews as "yourImageView", and execute that code just once, right after you have presented yourImageView on the screen. – John Smith Jul 23 '12 at 09:57
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); 
Sasi
  • 1,666
  • 2
  • 24
  • 44