设置UILabel背景颜色会导致应用崩溃

我有以下代码:

UIImageView *photo = [[[UIImageView alloc] initWithFrame:CGRectMake(title_bar.titleView.frame.origin.x+130, title_bar.titleView.frame.origin.y-12, 22.0, 22.0)] autorelease]; UIImage *theImage = [UIImage imageNamed:@"question mark icon"]; photo.image = theImage; UIView *new_view = [[UIView alloc] init]; [new_view addSubview:photo]; UILabel *new_label = [[UILabel alloc] initWithFrame:CGRectMake(title_bar.titleView.frame.origin.x-145, title_bar.titleView.frame.origin.y-12, 268.0, 22.0)]; [new_label setText:@"gregrgtg"]; [new_label setBackgroundColor:[UIColor clearColor]]; //COMMENTING THIS LINE OUT MAKES IT WORK [new_view addSubview:new_label]; title_bar.titleView = new_view; 

当背景颜色设置为clear时,程序SIGABRTs。 如果我注释掉那一行,它的工作正常(除了标签的背景只是白色)。 另外,如果我只是初始化标签而不是initWithFrame它,程序不会崩溃,但我的标签无法看到。

 UIImageView *photo = [[[UIImageView alloc] initWithFrame:CGRectMake(title_bar.titleView.frame.origin.x+130, title_bar.titleView.frame.origin.y-12, 22.0, 22.0)] autorelease]; UIImage *theImage = [UIImage imageNamed:@"question mark icon"]; photo.image = theImage; UIView *new_view = [[UIView alloc] init]; [new_view addSubview:photo]; title_bar.titleView = new_view;//this line by madhu UILabel *new_label = [[UILabel alloc] initWithFrame:CGRectMake(title_bar.titleView.frame.origin.x-145, title_bar.titleView.frame.origin.y-12, 268.0, 22.0)]; [new_label setText:@"gregrgtg"]; [new_label setBackgroundColor:[UIColor clearColor]]; //COMMENTING THIS LINE OUT MAKES IT WORK [new_view addSubview:new_label]; 

原因:

你已经添加了ur titlebar的titleview atlast,但之前提到过它们。