Flowlayout to flow non images


Can this be used to flow buttons and or labels instead of images?


Greetings Program!

Yes, you can use any type of UIView.

Using the FlowLayoutGettingStarted sample app, if you replaced the importImages method with this, you will have the flow layout showing a UIView with a label containing the filename of the image.

- (void)importImages {
    NSArray *imgPaths = [[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:@"Images"];
    for (NSString *path in imgPaths) {
        // Create image from filepath, and add it to the flow layout
        //UIImage *newImg = [[UIImage alloc] initWithContentsOfFile:path];
        //UIImageView *newView = [[UIImageView alloc] initWithImage:newImg];
	UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
	UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
	[newView addSubview:label];
	label.text = [[path lastPathComponent] stringByDeletingPathExtension];
	label.font = [UIFont fontWithName:@"Helvetica" size:10.0];
	[label sizeToFit];
        [self.myFlowLayout addManagedSubview:newView];