serdarsenol
serdarsenol

Reputation: 71

add label to UIButtons in iCarousel

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;

Upvotes: 0

Views: 769

Answers (1)

Nick Lockwood
Nick Lockwood

Reputation: 40995

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.

Upvotes: 1

Related Questions