I programmatically create a few UILabels in my app. In iOS 5 this code worked fine.
In iOS 6 the labels simply don’t seem to appear on the screen.
I don’t see any warnings, the code definitely executes, but no label.
I’ve tried searching for similar issues but can’t find anything. My labels have literally just disappeared.
Any help appreciated.
float popUpWidth = 700.0
//Add label
UILabel *label;
label = [[UILabel new] initWithFrame:CGRectMake(0,0,popUpWidth,50)];
label.text = @"Notes";
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = [UIColor blackColor];
label.textColor = [UIColor whiteColor];
//Add label to view
[self.view addSubview:label];
The problem is you are creating a label twice as wide as the devices screen, and setting a small amount of text to be centered thus causing the text to be off screen. Remember CGRect uses points not pixels. Additionally, I tested your code and had to replace “new” with “alloc” for it to work properly, I suggest you do the same.
The full correct line would be: