我在ViewController中实现了iCarousel方法,一切都正常,但有一件事,我想在旋转木马视图标签下面添加,对于每个图像,我想更改标签区域中的文本。这是我用来创建每个图像作为按钮的代码。
提前谢谢。
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];返回按钮;
- (void)carouselCurrentItemIndexDidChange:(iCarousel *)carousel;
使用该方法更新标签,因为每次转盘中居中的项目更新时,标签都会触发。
要真正确定要使用哪个标签文本,您可能需要创建第二个字符串数组来匹配您的图像数组。这样,您就可以使用carousel.currentItemIndex属性作为字符串数组的索引来选择正确的标签。