我已经创建了一个名为GraphView的自定义视图。当视图加载时,我得到的只是一个空白的黑屏。下面是我的代码:
在GraphViewController.m中:
@synthesize graphView, graphModel;
- (void)loadView
{
GraphView *aGraphView = [[GraphView alloc] initWithFrame:CGRectZero];
self.view = aGraphView;
self.graphView = aGraphView;
[aGraphView release];
}我不确定为什么当我尝试在GraphViewController.m中实现loadView时,我只得到一个黑屏
发布于 2011-03-19 02:17:52
我需要在loadView中将背景颜色设置为白色
- (void)loadView
{
GraphView *aGraphView = [[GraphView alloc] initWithFrame:CGRectZero];
aGraphView.backgroundColor = [UIColor whiteColor];
self.view = aGraphView;
self.graphView = aGraphView;
[aGraphView release];
}发布于 2011-03-14 10:08:54
您没有为GraphView对象设置框架:
GraphView *aGraphView = [[GraphView alloc] init];
UIView的指定初始化器是-initWithFrame:。执行如下操作(根据需要设置视图的大小/原点):
GraphView *aGraphView = [[GraphView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
https://stackoverflow.com/questions/5293976
复制相似问题