Drawing a line is very easy indeed, the "problem" is that drawing a line is an ill defined "request", you need to decide what color you want your line, what width etc.
in your view's drawRect method (assuming you're subclassing a view, that is you have a class that inherits UIView and you are making an instance of this class viewable):
in drawRect:
CGContextRef ctx = UIGraphicsGetCurrentContext(); //get the graphics context
CGContextSetRGBStrokeColor(ctx, 1.0, 0, 0, 1); //there are two relevant color states, "Stroke" -- used in Stroke drawing functions and "Fill" - used in fill drawing functions
//now we build a "path"
you can either directly build it on the context or build a path object, here I build it on the context
CGContextMoveToPoint(ctx, 0, 0);
//add a line from 0,0 to the point 100,100
CGContextAddLineToPoint( ctx, 100,100);
//"stroke" the path

중요한건 UIView에서 상속 받아야한다는것입니다. 그리고 기본적으로 생성되는 drawRect안에 설정.

계속에서 뭔가 에러가 났었는데 그 이유가 UIView를 상속 안받아서 그런듯하네요. 
Posted by KraZYeom

댓글을 달아 주세요