如何在UITableViewCell中制作字幕文本

时间:2014-03-08 14:46:24

标签: ios uitableview scroll

我用UILabel阅读了很多关于marque文本的信息,所以很容易制作。我对UITableViewCell有疑问。例如,我在标题中有大文本,我想在cell.textLabel或detailTextLabel中为我的大文本滚动。所以我也尝试过:

使用AutoScrollLabel类进行此操作 - 没有,并且在iOS 7中有一些问题。 我使用CBAutoScrollLabel - 但它只适用于UIlabel。

所以我无法粘贴一些示例代码,因为我只有简单的cell.textLabel来显示来自JSON o其他文本的文本。请帮助解决此问题,或者粘贴直接链接。

1 个答案:

答案 0 :(得分:1)

将单元格更改为自定义单元格,并为其指定“cell”

之类的标识符

现在您只需使用以下代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
     CBAutoScrollLabel *captionLabel = [[CBAutoScrollLabel alloc] initWithFrame:CGRectMake(10, 10, 100, 20)]; //can use any value you want here. 

     captionLabel.tag = 1;

     // setup your label here

     [cell addSubview:captionLabel];

     return cell;

}

如果您遇到可重用性问题,可以执行以下操作:

-(void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

     CBAutoScrollLabel *captionLabel = (CBAutoScrollLabel *)[cell viewWithTag:1];
     [captionLabel removeFromSuperview];

}
相关问题