我有我的UIView的代碼文件在故事板中設置視圖的自定義類。但是,當我運行應用程序並加載視圖時,什麼都沒有發生?我沒有得到任何我的NSLogs,沒有任何東西被吸引到屏幕上?有誰知道我做錯了什麼?我沒有正確地使用某些東西嗎?UIView無法正確加載?
我的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