首页 文章

将标签添加到iCarousel中的UIButtons

提问于
浏览
0

我在我的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];返回按钮;

1 回答

  • 1

    iCarousel有一个委托方法:

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

    使用该方法更新标签,因为每次轮播中的居中项目更新时它都会触发 .

    要实际计算出要使用的标签文本,您可能需要创建第二个字符串数组以匹配您的图像数组 . 这样,您可以使用carousel.currentItemIndex属性作为strings数组的索引来选择正确的标签 .

相关问题