我的 UIView 的代码文件在情节提要中设置了视图的自定义类。但是,当我运行应用程序并加载视图时,什么都没有发生?我没有得到任何 NSLog,屏幕上没有任何内容?有谁知道我做错了什么?我没有正确地处理某些事情吗?
我的 UIView 代码:
- (id)initWithFrame:(CGRect)frame
{
NSLog(@"Drawling area loaded");
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void)drawRect:(CGRect)rect
{
CGPoint dotOne = CGPointMake(1, 1);
[squareLocations addObject:[NSValue valueWithCGPoint:dotOne]];
CGPoint dotTwo = CGPointMake(10, 10);
[squareLocations addObject:[NSValue valueWithCGPoint:dotTwo]];
CGPoint dotThree = CGPointMake(100, 100);
[squareLocations addObject:[NSValue valueWithCGPoint:dotThree]];
int numby = [squareLocations count];
for (int i = 0; i < numby; i++)
{
NSValue *pointLocation = [squareLocations objectAtIndex:i];
CGPoint tmpPoint = [pointLocation CGPointValue];
CGRect tmpRect = CGRectMake(tmpPoint.x, tmpPoint.y, 10, 10);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 5.0);
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGFloat components[] = {0.0, 0.0, 1.0, 1.0};
CGColorRef color = CGColorCreate(colorspace, components);
CGContextSetStrokeColorWithColor(context, color);
CGContextMoveToPoint(context, tmpPoint.x, tmpPoint.y);
CGContextAddLineToPoint(context, 300, 400);
CGContextStrokePath(context);
}
}
@end