Domanda

I am trying to implement a mockup like this. However, I'm not sure which view controller I should be using for something like this? I tried UICollectionViewController but that puts cells of fixed width on each row. As you can see in my mockup, at some places I have a label taking all width and in other places I have three labels taking up the width.

enter image description here

È stato utile?

Soluzione

You can use the simple UIViewController and drag the labels manually in the Storyboard. In order to make the rectangular label to round edged labels, you can create a IBOutletCollection of all those labels and iterate through the array, get each label's layer and set the corner radius to appropriate value. e.g:

 @property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *customLabels;

As customLabels is an NSArray so it doesn't have a layer property. You can do it like this:

  for (UILabel *label in customLabels) {
        label.layer.cornerRadius = 5.0;
    }

Altri suggerimenti

I'd stick with a plain UIViewController based controller.

The collection view is more for dynamic content like a bunch of photos. To do this with a collection view would take a bunch of unnecessary work.

With this layout, just lay the objects out manually on the storyboard and then you can just use the regular constraints if you need to resize dynamically and that will do just fine.

You can just use a UIViewController and set the buttons up appropriately in Interface Builder or programmatically.

If you take the latter approach, you can do something like this in your view controller

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

// be sure to do this step or you won't see your button
button.frame = CGRectMake(...);

// Customize your button here

[self.view addSubview:button

See this documentation for information on CGRectMake if you aren't familiar

Edit: I'm not sure if this approach will handle orientation changes appropriately. I suspect it would if you calculate the frame instead of hardcoding values. I don't have the ability to test that right now unfortunately.

Edit again: I didn't realize this was tagged for RubyMotion. I'm not familiar with that api so my code example may not be relevant.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top