滚动标签

Scrolling the label

我正在为自己编写一个小应用程序,但遇到了一些麻烦。 我无法使用 ScrollView 滚动标签。通过读取文本文件出现标签。

我展示了我的部分代码。

.py代码:

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.uix.label import Label
from kivy.uix.popup import Popup
from kivy.uix.button import Button
from kivy.uix.scrollview import ScrollView

class GeneralForm(TabbedPanel):
    txt_show = ObjectProperty()

    def SHOW_CONTENT(self):
        FILE=open('data')
        A=FILE.read()
        self.txt_show.text=A

class TimeTable(App):

    def build(self):
        return GeneralForm()

if __name__ == '__main__':
    TimeTable().run()

.kv代码:

<GeneralForm>:
    do_default_tab: False
    txt_show:txt1
    TabbedPanelItem:
        text: 'Mon'
        on_release: root.SHOW_CONTENT()
        BoxLayout:
            orientation: 'vertical'
            ScrollView:
                size: self.size
                Label:
                    id:txt1
                    text: ''
                    size_hint_y: None
            BoxLayout:
                Button:
                    text: 'Edit'
                Button:
                    text: 'Exit'
    TabbedPanelItem:
        text: 'Tue'
    TabbedPanelItem:
        text: 'Wed'

"data" 文件是一个简单的 txt 文件,其中有很多行文本。 当该文本显示在标签中时 - 它被截断了。

如何为标签中的文本添加滚动条?

提前致谢。

ScrollView:
    Label:
        id:txt1
        text: ''
        text_size: self.width, None  # Set the text wrap box width
        size_hint_y: None
        height: self.texture_size[1]  # Set the Label height to the text height

转到站点 https://github.com/cbpowell/MarqueeLabel 并下载。 将 .m 和 .h 文件复制到您的项目并添加石英核心框架。 转到您的 .h 文件并导入 marquee.h 文件。

#import <UIKit/UIKit.h>
#import "MarqueeLabel.h"

@interface PlayerViewController : UIViewController

然后在 UIViewController 中创建一个标签,然后按住 ctrl 将其拖到 .h 文件中。保留出口选项,写下您想要的标签名称,将 UILabel 更改为 MarqueeLabel。 它将是这样的:

@property (strong, nonatomic) IBOutlet MarqueeLabel *nomeMusicaLabel;

Select 视图中的标签,转到屏幕右侧的实用程序栏,转到身份检查器(第三个按钮),将 class 更改为 MarqueeLabel。

转到您的 .m 文件并编写以下代码:

nomeMusicaLabel.text = @"Write your text here";
self.nomeMusicaLabel.marqueeType = MLContinuous;
self.nomeMusicaLabel.scrollDuration = 15.0;
self.nomeMusicaLabel.animationCurve = UIViewAnimationOptionCurveEaseInOut;
self.nomeMusicaLabel.fadeLength = 10.0f;
self.nomeMusicaLabel.leadingBuffer = 30.0f;
self.nomeMusicaLabel.trailingBuffer = 20.0f;

在 MarkeeLabel zip 文件中,有包含许多其他类型的 scrool 文本的项目。