自编了一个跑马灯,自适应高度和宽度,就一个label显示。
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,200, 0, 100)];
label.backgroundColor = [UIColor redColor];
label.font = [UIFont systemFontOfSize:15];
label.text = @"简书简书简书简书简书书简书书简书简书简书书简书书简书简书ABC";
CGSize size = [label.text boundingRectWithSize:CGSizeMake(0, label.frame.size.height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:label.font} context:nil].size;
label.frame = CGRectMake(0, 200, size.width, size.height);
[self.view addSubview:label];
CGRect frame = label.frame;
frame.origin.x = self.view.bounds.size.width;
label.frame = frame;
[UIView beginAnimations:@"testAnimation"context:NULL];
[UIView setAnimationDuration:25];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationRepeatAutoreverses:NO];
[UIView setAnimationRepeatCount:HUGE_VALF];
frame = label.frame;
frame.origin.x =-label.frame.size.width;
label.frame = frame;
[UIView commitAnimations];