I am new to iOS development, I am trying to create a scroll title, for example, the Engadget application for iPhone, I created a custom UIView to act as a subview for UIScrollView, the subheading layout algorithm seems to be fine as I can scroll through the subheadings, change the color programmatically background in the views, but the problem is that I do not see anything from the content, only gray backgrounds, what am I doing wrong?
Thanks in advance.
This is my code:
Promotion is a UIView with two labels and a UIImageView.
- (void)layoutScrollSubViews { promoted *view = nil; NSArray *subviews = [sView1 subviews]; // reposition all image subviews in a horizontal serial fashion CGFloat curXLoc = 0; for (view in subviews) { if ([view isKindOfClass:[promoted class]] && view.tag > 0) { CGRect frame = view.frame; frame.origin = CGPointMake(curXLoc, 0); frame.size.height = kScrollObjHeight; frame.size.width = kScrollObjWidth; view.frame = frame; curXLoc += (kScrollObjWidth); } } // set the content size so it can be scrollable [sView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [sView1 bounds].size.height)]; } // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad{ NSUInteger i; for (i = 1; i <= kNumImages; i++) { promoted *p = [[promoted alloc] initWithFrame:CGRectMake(0, 0, 320, 187)]; p.title.text = @"Test 1"; p.num.text = @"1/1"; p.num.backgroundColor = [UIColor whiteColor]; // setup each frame to a default height and width, it will be properly placed when we call "updateScrollList" p.backgroundColor = [UIColor colorWithRed:(.9/i) green:(.9/i) blue:(.9/i) alpha:1]; p.tag = i; // tag our images for later use when we place them in serial fashion [sView1 addSubview:p]; [p release]; } [self layoutScrollSubViews]; [super viewDidLoad]; }
source share