0

I am a novice to objective-c and developing my first app, a notification-center widget, compiled by "theos" to .deb

Its pretty straightforward: I want to create an Uiscrollview, to scroll (horizontally) through multiple pages, which are added as Uiimage subviews to the scrollview. On one page I add uibuttons to the uiimageview - works!

I tried, just for testing, an uislider on another - works!

All elements are shown as intended and can be controlled, but when I add labels, no matter to what page, it only shows me a white filled rect on the left edge of the uiimageview:

Buttons vs. buggy label

The code is as simple as:

creating the scrollview in the -(void)init

scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT)];
scrollView.pagingEnabled = YES;
scrollView.userInteractionEnabled = YES;
scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
scrollView.showsHorizontalScrollIndicator = NO;

Creating the page subview in -(void)loadFullView

page0 = [[UIImageView alloc] initWithImage:stretchableBgImg];
page0.frame = CGRectMake(PAGEVIEW_OFFSET, 0.0f, VIEW_WIDTH-2*PAGEVIEW_OFFSET, VIEW_HEIGHT);
page0.autoresizingMask = UIViewAutoresizingFlexibleWidth;
page0.userInteractionEnabled = YES;

somewhere later:[scrollView addSubview:page0]; [_view addSubview:scrollView];

Creating label and adding it to the page

UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(PAGEVIEW_OFFSET,0,VIEW_HEIGHT/2,VIEW_WIDTH-2*PAGEVIEW_OFFSET)];
label.text = @"Message";
[page0 addSubview:label];
[label release];

What am I missing? Any help appreciated!

flok3r
  • 1
  • 1
  • 2
  • Try setting the UILabel's background color to clear. Ex. [label setBackgroundColor:[UIColor clearColor]]; – Jonathan Jul 23 '13 at 20:48
  • Hm, now the block is gone (clear), the page appears totally empty. But there should be text and the label should have the size of the page.. (VIEW_WIDTH = 320, PAGEVIEW_OFFSET = 2) – flok3r Jul 23 '13 at 20:57
  • by the way, adding label.textAlignment = NSTextAlignmentCenter; doesnt change the "block" position at all, could be useful to know – flok3r Jul 23 '13 at 21:01
  • NSTextAlignmentCenter center aligns the text within the UILabel. To change the position of the UILabel adjust the first 2 values in the CGRect. Ex. CGRectMake(xPosition, yPosition, width, height). Try increasing the X value in the CGRect – Jonathan Jul 23 '13 at 21:04
  • Also, what are the values of VIEW_HEIGHT, VIEW_WIDTH, PAGEVIEW_OFFSET? – Jonathan Jul 23 '13 at 21:09
  • Here is a centered UIlabel http://stackoverflow.com/questions/4457779/uilabel-center-contents – Goca Jul 23 '13 at 21:11
  • 1
    Typical noob mistake :) I actually know what you are pointing me at, but I just reread the code.. carefully .. and noticed, that the x-width is set to the intended y-height and vice versa.. because of the multiline setting being disabled the text did not show up. thx Jonathan – flok3r Jul 23 '13 at 21:11
  • No problem! I'm glad you figured it out! – Jonathan Jul 23 '13 at 21:17

0 Answers0