开发者

how to make UITableViewCell contentview mask UILabel to create core animation scrolling text

开发者 https://www.devze.com 2023-04-05 17:04 出处:网络
I\'m trying to create a UITable in which the cells display some text and, when the text is larger than the cell\'s contentview (that is, up to the accesory type), the text should do a scrolling animat

I'm trying to create a UITable in which the cells display some text and, when the text is larger than the cell's contentview (that is, up to the accesory type), the text should do a scrolling animation to show all of itself.

I've managed to sort of pull it off. That is, I get the text to scroll, but:

  • I tried using the cell's contentview bounds to clip the text, so that it scrolls but clips at both the left end of the cell and the right end of the content view just before the accessory. But this doesn't work: the contentview always has a width of the entire iphone screen? (320).

  • I also tried adding a new UIView alltogether to the contentView, with a set size. Still, it doesn't clip.

Basically, I g开发者_StackOverflowet the text to scroll but it scrolls past (and over) the accessory and the left edge.

Any help is greatly appreciated.


Have you tried setting the clipsToBounds property on any views to YES? Probably won't work on the contentView but if you use the fixed size UIView subview idea and set its clips to bounds, I think it should work. Something like this:

UIView *subview = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 250.0, myTableViewCell.contentView.bounds.size.height)];
subview.clipsToBounds = YES;
[myTableViewCell.contentView addSubview:subview];

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 10000.0, subview.bounds.size.height)];
label.text = @"Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.";
[subview addSubview:label];

// make animation happen

[subview release];
[label release];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号