4

Basically, I have a view that can have an unlimited amount of UIViews inside of it. I want to be able to set self.numberOfSections = 8 or self.numberOfSections = 2 and then have that same number of UIImages generated respectively that can then be manipulated.

Currently I have many IBInspectible images in my code that appear no matter if I have 2 numberOfSections or 100 numberOfSections. I would like to somehow be able to create UIImages based off of my numberOfSections number.

rotaryWheelView

storyBoardInspect

If I set Number Of Sections to 2 here - I can set the images in the story board, but all the other IBInspectable elements appear too that won't be used because there are only 2 sections. Is there a way to only have the ones that are needed appear? I want to set images in the storyboard. Is there a way to refactor this down so as not to have so many IBInspectables?

This is how I set the images to the various programmatically generated views in code.

-(void)drawRect:(CGRect)rect

    for (int i = 0; i < self.numberOfSections; i++) {
       NSString *rotaryName = [NSString stringWithFormat:@"rotaryImage%d", i + 1];
       id rotaryNameValue = [self valueForKey:rotaryName];
       [self.sectorView setValue:rotaryNameValue forKey:@"image"];
    }
}
HannahCarney
  • 3,441
  • 2
  • 26
  • 32
  • you cant generate properties once the compiler start compiling the program. They have to be set before you run the program. – Teja Nandamuri Oct 13 '15 at 16:18
  • any way to add an IBInspectable to a property later in the view.m file? So it already exists @property (nonatomic) UIImage *rotaryImage1 and then later I can add IBInspectable to it. – HannahCarney Oct 13 '15 at 16:25
  • 1
    array, ibouletcollection, data source. But definitely not generating properties. – Sulthan May 06 '16 at 12:29

1 Answers1

5

First of all I would say that there is a flaw in your design pattern. If you have that many IBInspectable UIImageView instances, you probably should be using an IBOutletCollection.

Secondly, what your asking is not possible. Why not create a single IBInspectable value type to set the number of sections from the storyboard, and generate your UIImageView objects programmatically from that number?

@property (nonatomic, assign) IBInspectable int *sections;

Interface Builder

JAL
  • 41,701
  • 23
  • 172
  • 300
  • Okay yeah I was unaware of IBOutletCollection existing. I want to be able to set the images in the storyboard but basically it always shows all the IBInspectables despite only having 2 numberOfSections. – HannahCarney May 06 '16 at 13:00
  • @HannahLouisaCarney I'm not sure what you're asking. You want an `IBInspectable int` that will change the number of views generated for you in Interface Builder? That is not possible, you will need to add your views programmatically. – JAL May 06 '16 at 13:03
  • I suppose I want only two IBInspectable RotaryImages to appear in the storyboard to set, if you have numberOfSections set to 2, and 8 to appear if you have set it to 8. Since you can have unlimited images, but I can only type limited IBDesignables in my code. – HannahCarney May 06 '16 at 13:07