I'm trying to make my main ViewController with a custom view draw multiple custom UIView's to the main view, but somehow they are not drawing, I'm trying to draw dots.
My code is:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
MyCustomView *myView = (MyCustomView *)self.view;
myView.xAxisLabel1 = @"customlabels 1";
myView.xAxisLabel2 = @"customlabels 2";
myView.xAxisLabel3 = @"customlabels 3";
myView.xAxisLabel4 = @"customlabels 4";
CustomDotView *newDot = [[CustomDotView alloc] initWithPointAtXCord:10 andYCord:10 withRadius:10 andColor:[UIColor redColor]];
[self.view addSubview:newDot];
}
But this is not working, I wonder if the constructor of my CustomDotView is correct or I'm doing something incorrectly
This is my CustomDotView constructor
-(id)initWithPointAtXCord:(float)xCord andYCord:(float)yCord withRadius:(float)radius andColor:(UIColor *)color {
self = [super init];
self.color = color;
self.xCordenate = xCord;
self.yCordenate = yCord;
self.radius = radius;
return self;
}
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, color.CGColor);
CGContextSetFillColorWithColor(context, color.CGColor);
CGRect currentRect = CGRectMake(xCordenate, yCordenate, radius * 2 , radius * 2);
NSLog(@"draw point?");
CGContextAddEllipseInRect(context, currentRect);
CGContextDrawPath(context, kCGPathFillStroke);
}
Any suggestions?