我正在使用Nick Lockwood的iCarousel类来显示使用该方法存储在数组中的一系列图像
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
{
//create new view if no view is available for recycling
if (view == nil)
{
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100.0f, 100.0f)];
((UIImageView *)view).image = [images objectAtIndex:index];
view.contentMode = UIViewContentModeScaleAspectFit;
}
}
我现在想要显示存储在每个图像下方(并居中)的类似数组中的文本,就像电影标题放在imDB应用程序的缩略图下一样。任何帮助都会非常感激。提前致谢!
答案 0 :(得分:3)
您可以将UILabel
添加到view
,即
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
{
//create new view if no view is available for recycling
if (view == nil)
{
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100.0f, 100.0f)];
((UIImageView *)view).image = [images objectAtIndex:index];
view.contentMode = UIViewContentModeScaleAspectFit;
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 70, 100.0f, 30.0f)];
lbl.text = [titlesArray objectAtIndex:index]; // Here you can add titles to label
/* Here you can code the EFX. */
[view addSubview:lbl];
}
}