可调整大小的UILabel在屏幕上滚动 [英] Resizable UILabel which scrolls across the screen

查看:165
本文介绍了可调整大小的UILabel在屏幕上滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对,我想尝试在其中显示文字的标签(显然已经完成),它在屏幕上滚动。

Right, I'm trying to get a label with text in it (done already obviously), which scrolls across the screen.

输入的文本该标签由UITextField和UIButton完成。这更新很好。

The text that is input into the label is done by a UITextField and a UIButton. This updates fine.

但是我想让UILabel根据文本输入量调整大小,以便让大量的文本在屏幕上滚动。

But I'm trying to get the UILabel to resize accordingly to the amount of text input, so that the WHOLE lot of text scrolls across the screen.

这是我目前用于滚动标签的代码:

This is the code I have at the moment for the scrolling label:

[lblMessage setText: txtEnter.text];

CABasicAnimation *scrollText;

scrollText=[CABasicAnimation animationWithKeyPath:@"position.x"];
scrollText.duration = 3.0;
scrollText.repeatCount = 10000;
scrollText.autoreverses = NO;
scrollText.fromValue = [NSNumber numberWithFloat:500];
scrollText.toValue = [NSNumber numberWithFloat:-120.0];

[[lblMessage layer] addAnimation:scrollText forKey:@"scrollTextKey"];

问题是,有时开始在屏幕中间滚动,

The problem is, sometimes is starts scrolling in the middle of the screen, and sometimes vanishes before it has fully gone acrosss.

由于标签是一个大小,它也会剪切文字..我不知道如何更改这个。

It also cuts of text due to the label being one size.. I don't know how to change this.

提前感谢。

Dom

推荐答案

我相信类似于此问题的解决方案将适用于这种情况。

I believe something similar to the solution for this question would work for this case.

您可以将UILabel嵌入UIScrollView,将UIScrollView设置为要显示的标签的最大大小屏幕一次。 UIScrollView将需要使用其showsHorizo​​ntalScrollIndicator和showsVerticalScrollIndicator属性来关闭其滚动指示器。在文本更改时,您可以执行以下操作:

You could embed the UILabel in a UIScrollView, with the UIScrollView set to the max size of the label that you want to display on the screen at one time. The UIScrollView would need to have its scroll indicators turned off using its showsHorizontalScrollIndicator and showsVerticalScrollIndicator properties. On a change of text, you could do the following:

[lblMessage setText: txtEnter.text];
[lblMessage sizeToFit];
scrollView.contentSize = lblMessage.frame.size;

,然后跟上面链接的问题中描述的平移动画代码,到UILabel的最右边。这将导致文本以恒定速率在标签上滚动。如果你想让标签回滚到开头,你可以使用动画块开头的UIView setAnimationRepeatAutoreverses:和setAnimationRepeatCount:方法。

followed by the panning animation code as described in the above-linked question, with the frame to be panned to being the far right of the UILabel. This would cause the text to scroll at a constant rate across the label. If you want the label to scroll back to the beginning, you could use the UIView setAnimationRepeatAutoreverses: and setAnimationRepeatCount: methods in the beginning of your animation block.

这篇关于可调整大小的UILabel在屏幕上滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆