ICarouse动态标签宽度

时间:2017-01-17 07:30:34

标签: ios objective-c iphone xcode mobile

需要显示动态宽度的项目。我试过波纹管代码。但它的物品之间的空间也越来越大。这是我的代码:

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
{

    UILabel *label = [[UILabel alloc]init];
    label.font = [UIFont systemFontOfSize:13];
    label.text = [timelineMediaArray objectAtIndex:index];
    label.textAlignment = NSTextAlignmentCenter;

    CGFloat width = [label.text sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13 ]}].width;
    label.frame = CGRectMake(0, 0, width+20,30);
    label.backgroundColor = [UIColor redColor];
    label.textColor = [UIColor whiteColor];


    return label;

} 

0 个答案:

没有答案