1

Here,when button taps label count is increments & decrements.While label count increments images will be added by respective count.here my code for incrementing label count

if (counter >= 9 )
    return;
[_count setText:[NSString stringWithFormat:@"%d",++counter]];

but i need to display while incrementing the label count then automatically increments images one by one.like this

enter image description here

Can you please help me how can i implement,thank you.

iGatiTech
  • 2,306
  • 1
  • 21
  • 45
G.P.Reddy
  • 556
  • 3
  • 20

4 Answers4

3

Add a UIScrollView in place of where you want to show images. When click on '+' button, call following method by passing the 'counter' value.

-(void)addImage:(int) count {
  UIScrollView * scView = [[UIScrollView alloc] init];
  scView.frame = CGRectMake(30, 60, self.view.frame.size.width, 60);
  UIButton * btn;
  UIImageView * imgV;
  float imgWidth = 44;
  for(int i=0;i<count;i++) {
    imgV = [[UIImageView alloc] init];
    imgV.frame = CGRectMake(i*imgWidth, 0, imgWidth, 44);
    imgV.image = [UIImage imageNamed:@"gitar"];
    [scView addSubview:imgV];
  }
  [scView setContentSize:CGSizeMake(imgWidth*count, 50)];
  [scView setBackgroundColor:[UIColor redColor]];
  [self.view addSubview:scView];
}

- (IBAction)descrese:(id)sender {
   counter -= 1;
   [self addImage:counter];
}

- (IBAction)btnTap:(id)sender {
    counter += 1;
    [self addImage:counter];
}

This adds as many images as you want in horizontal scroll view.

AskIOS
  • 918
  • 7
  • 19
  • Thank you @Bharath it's working,and for decrement of images how can i implement – G.P.Reddy Jan 19 '16 at 04:20
  • for(scView in [scView subviews]) { [imgV removeFromSuperview]; } – G.P.Reddy Jan 19 '16 at 04:20
  • @iOS2340 Simply pass your counter value to above method all the times either decrement or increment, it will add those many images in scrollview. – AskIOS Jan 19 '16 at 06:28
  • I tested its working fine for me. I'm 2 more methods in my answer , one for decrement image count and other is for increment image count. hope that will help you. – AskIOS Jan 19 '16 at 07:11
0

use a uiscrollview with cells of images, that simple.

DeyaEldeen
  • 10,847
  • 10
  • 42
  • 75
0

Use UIScrollView. As number of elements is increasing/decreasing: 1) increse/deacrease UIScrollView size respectively 2) add/remove elements

Max
  • 711
  • 5
  • 13
0

I guess, the screenshot was taken from MMT app. They're using this feature in their app. I believe, they might have developed a separate control to handle this thing, where they can only pass few arguments like image to show (people), count etc.

You can also develop such kind of UI with following way:

  • Create a custom view, take a UICollectionView inside it, take argument of image to show and number of rows count, fixed the cell size in layouts. Add a method which will reloads UI (inside logic: reloading UICollectionView) to refresh content when user taps on [ + ] or [ - ] button. Why, we're not taking UIScrollView, with it we can't reuse contents. I believe this step will need you to create everything programmatically.

  • When user taps on [ + ], you should increase width of our custom view, inside you should override layoutSubview method to update frame of UICollectionView as well. You may require to refresh(reload) cells inside UICollectionView.

  • Do reverse when user taps [ - ].

  • You may require to set some logic so user can't add more/less numbers when selection.

This is just an idea, you may require to check each cases which the reference app has having.

Community
  • 1
  • 1
Hemang
  • 26,840
  • 19
  • 119
  • 186