в моя ViewController имам бутон:
- (IBAction)drawLineClick:(id)sender
{
CGRect rect;
rect.origin.x = 20.0f;
rect.origin.y = 40.0f;
rect.size.width = 100.0f;
rect.size.height = 100.0f;
//draw line
DrawLine *drawLine = [[DrawLine alloc] initWithFrame:rect];
[self.view addSubview:drawLine];
}
в моя клас DrawLine просто рисувам линия:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[super setBackgroundColor:[UIColor clearColor]];
}
return self;
}
- (void)drawRect:(CGRect)rect
{
// Drawing code
[self drawLine];
}
- (void)drawLine
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGContextSetLineWidth(context, 3.0);
CGContextMoveToPoint(context, 0, 0);
CGContextAddLineToPoint(context, 50, 50);
CGContextStrokePath(context);
}
Това работи чудесно, но не е променливо. Всеки път е една и съща линия. Как мога да предам цвета на линията, ширината на линията и т.н. от ViewController към класа DrawLine, така че да мога да рисувам различни линии?
Благодаря.