I’m trying to add a UILabelto my UIScrollView, but it doesn’t show up at all. I’ve also tried adding a new UIView with red background color, which works just fine (scrolling and zooming both work).
I create my UIScrollViewlike this:
scrollView_ = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, screenW, screenH)];
[scrollView_ setBounces:YES];
[scrollView_ setMinimumZoomScale:1.0];
[scrollView_ setMaximumZoomScale:1.0];
[scrollView_ setBackgroundColor:[UIColor clearColor]];
and my UILabel like this:
aboutTextLabel_ = [[UILabel alloc] init];
aboutTextLabel_.numberOfLines = 0;
[aboutTextLabel_ setFont:[UIFont fontWithName:@"ChalkDust" size:11]];
[aboutTextLabel_ setTextColor:[UIColor whiteColor]];
[aboutTextLabel_ setText:@"my text"];
[aboutTextLabel_ setBackgroundColor:[UIColor clearColor]];
[aboutTextLabel_ setFrame:CGRectMake(10,10,300,300)];
I then add it like this:
[scrollView_ addSubview:aboutTextLabel_];
[scrollView_ setContentSize:contentSize]; // precomputed
However, this gives me a blank screen.
When I create the aboutTextLabel as a local variable, the exact same code works.
aboutTextLabel_ is not defined as a @property, but in the interface declaration.
set
aboutTextLabel_.numberOfLines = 1;instead of
Also add scrollView_ to the main view if you have not added like:-