UILabel里面的视图滚动被截断

时间:2015-06-29 13:21:52

标签: ios objective-c

我使用UILabel在小视图中滚动文本,滚动然后在一段时间后重复。 现在发生了什么,是文本的长度,被截断,所以而不是显示的全名,它显示xxxxxxxxxx然后..最后,有没有办法扩展它,所以它显示整个文本而不截断? / p>

-(void)text_1_Move_animetion
{
    text_1_lable.frame = CGRectMake(text_1_lable.frame.size.width, text_1_lable.frame.origin.y, text_1_lable.frame.size.width, text_1_lable.frame.size.height);

    [UIView animateWithDuration:8.0 animations:^{
        text_1_lable.frame = CGRectMake(-text_1_lable.frame.size.width, text_1_lable.frame.origin.y, text_1_lable.frame.size.width, text_1_lable.frame.size.height);
    }];
    [self performSelector:@selector(text_1_repet) withObject:self afterDelay:8.0];


}
-(void)text_1_repet
{
    text_1_lable.frame = CGRectMake(text_1_lable.frame.size.width, text_1_lable.frame.origin.y, text_1_lable.frame.size.width, text_1_lable.frame.size.height);


    [UIView animateWithDuration:8.0 animations:^{
        text_1_lable.frame = CGRectMake(-text_1_lable.frame.size.width, text_1_lable.frame.origin.y, text_1_lable.frame.size.width, text_1_lable.frame.size.height);
    }];


    [self performSelector:@selector(text_1_Move_animetion) withObject:self afterDelay:8.0];
}

如果我将.xib文件中的换行符设置为break,则不会截断...它会显示更多内容,但会在结束时切断。

1 个答案:

答案 0 :(得分:2)

您可以计算字符串的宽度,并查看宽度是否大于label.bounds.size.width

NSString UIKit Additions有几种方法可以用特定字体计算字符串的大小。但是,如果您的标签有minimumFontSize,则允许系统将文本缩小到该大小。在这种情况下,您可能希望使用sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode: