0
votes

I implemented iCarousel method in my ViewController and all is working properly but there is one thing, i want to add below the carousel view label and for each image, i want to change the text in this label area. Here is my code I used for creating each image as button.

Thanks in advance.

UIImage *buttonImage =[NSArray arrayWithObjects:[UIImage imageNamed:@"Hotels.png"],
                       [UIImage imageNamed:@"image2.png"],
                       [UIImage imageNamed:@"image3.png"],
                       [UIImage imageNamed:@"image4.png"],
                       [UIImage imageNamed:@"image1.png"],
                       [UIImage imageNamed:@"FastFood.png"],
                       [UIImage imageNamed:@"Taxi.png"],nil];

UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 200.0f, 200.0f);

[button setImage:[buttonImage objectAtIndex:index]forState:UIControlStateNormal]; [button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]; return button;

1
Please format the code properly. UIImage object is initialed with NSArray.parilogic
Sorry for improper format, it is my first post here. Instead NSArray, what else i can use to create buttons with images in iCarousel?serdarsenol

1 Answers

1
votes

iCarousel has a delegate method:

- (void)carouselCurrentItemIndexDidChange:(iCarousel *)carousel;

Use that method to update your label as it will fire every time the centred item in the carousel updates.

To actually work out which label text to use, you probably want to create a second array of strings to match your array of images. That way you can use the carousel.currentItemIndex property as the index into the strings array to select the correct label.