Generate more properties when the number of other objects increases.

Basically, I have a view that can have an unlimited amount of UIView inside. I want to be able to set self.numberOfSections = 8or self.numberOfSections = 2, and then create the same amount UIImages, generated accordingly, that can be processed.

Currently, I have many images IBInspectiblein my code that appear regardless of whether I have 2 numberOfSections or 100 numberOfSections. I would like to somehow create UIImages, based on my numberOfSections number.

rotaryWheelView

storyBoardInspect

If I set Number of Sections to 2 here, I can set the images in the story panel, but all other IBInspectable elements will also be displayed, because there are only 2 sections. Is there a way to get only those that are needed? I want to set the images in a storyboard. Is there a way to reorganize this so that there are not so many IBInspectables?

This is how I set images to 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"];
    }
}
+4
source share
1 answer

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

-, . IBInspectable, UIImageView ?

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

Interface builder

+5

Source: https://habr.com/ru/post/1611467/


All Articles