我正在尝试使用自定义视图使我的主 ViewController 将多个自定义 UIView 绘制到主视图,但不知何故它们没有绘制,我正在尝试绘制点。
我的代码是:
- (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];
}
但这不起作用,我想知道我的 CustomDotView 的构造函数是正确的还是我做错了什么
这是我的 CustomDotView 构造函数
-(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);
}
有什么建议么?