UIView mobility is not displayed in UIScrollView

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]; } 
+4
source share
2 answers

You can do two things: 1. Add your kind of image and labels directly to scrollView 2. also assign your shortcut and ImageView before adding them to your UIView (and remember to free them when the requirement is completed, in the corresponding area)

0
source

According to my experience, UIScrollView is a weird buggy released by an apple. I don't know why it behaves abnormally when added through a nib file. I always try to create a UIScrollView programmatically and add a subspecies to it, while also highlighting them programmatically.

It may sound strange, but it works for me most of the time!

0
source

All Articles