Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dipaliP

macrumors newbie
Original poster
Oct 6, 2008
28
0
first i want to clear that my English is not so good.
Here is my code to display line on UIView object
I am using XCode 10.5 Cocoa Touch App.
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 3.0);
CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);
CGContextMoveToPoint(context, 10.0, 30.0);
CGContextAddLineToPoint(context, 310.0, 30.0);
CGContextStrokePath(context);
[self setNeedsDisplay];


its not displaying line.

If anyone have idea, pliz help me & not interested in reading any comments...
 

dipaliP

macrumors newbie
Original poster
Oct 6, 2008
28
0
context variable not initializing.
As i am drawing it on view i haven't pushed CGContext.
I think there would be any other way to initialise context variable.

I am using following statement to initialize.
CGContextRef context = UIGraphicsGetCurrentContext();
 

dipaliP

macrumors newbie
Original poster
Oct 6, 2008
28
0
I tried with writing all code related to creating and displaying line in drawRect:rect
and call drawRect:rect method to work.
But again same problem i got that is context is not getting initialized.

I am not getting any other way to initialize it.
Any help is there from anyone?
sorry for my poor English.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
You should never need to call drawRect: directly. You call setNeedsDisplay: and at some point soon the system will call drawRect: with a correctly setup context etc.

As per usual this is all covered in the excellent documentation provided by Apple. I suggest you read it as you are clearly not a proficient Cocoa programmer.
 

dipaliP

macrumors newbie
Original poster
Oct 6, 2008
28
0
I am adding new view in nib file and displaying that view on some event of previous view's control. Its goes fine up to displaying that newly added view but control does not enters into view's drawrect: method.

When i tried it with default view it displays all lines.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.