2
我有以下代碼:設置的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;
當背景色設置爲清除,該程序SIGABRTs。如果我將該行註釋掉,它可以正常工作(除了標籤的背景只是白色)。另外,如果我只是初始化標籤而不是initWithFrame,那麼程序不會崩潰,但我的標籤不可見。
用上面的代碼檢查 –
謝謝,工作!如果你不介意,你知道它爲什麼有效嗎?我不認爲這會有所作爲。 – Outback