0

Need to display items with dynamic widths. i have tried bellow code. but its increasing spaces between items too. here is my code:

- (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;

} 
  • check this may helps ..http://stackoverflow.com/questions/3527494/how-to-calculate-uilabel-width-based-on-text-length – vaibhav Jan 17 '17 at 08:06
  • Ya it is working but, increasing space between items also. that should not happen. space between items should be constant. @vaibhav – Raghava Naidu Jan 17 '17 at 08:18

0 Answers0