I want to display a text with a lot of lines. I added a multiline-label to a scroll view, but it didn't show anything. Looks like this is not the correct way to use the scroll view. How to use scroll view so that users can drag down to see more text?
我想显示一个有很多行的文本。我在滚动视图中添加了多行标签,但它没有显示任何内容。看起来这不是使用滚动视图的正确方法。如何使用滚动视图以便用户可以向下拖动以查看更多文本?
4 个解决方案
#1
10
You can just use a UITextView. It's a child of UIScrollView, and if you set it's text property to an amount of text that does not fit within it's frame, the view will become scrollable.
你可以使用UITextView。它是UIScrollView的子项,如果将其text属性设置为不适合其框架的文本量,则视图将变为可滚动。
#2
21
Apple's UIScollView documentation is quite good, you should start there and understand the class.
Apple的UIScollView文档相当不错,你应该从那里开始理解这门课程。
Think of a Scrollview as a large view surface over which the screen slides*. You can add subviews to the scrollview and then scrolling is like positioning the screen over the scrollview - the screen acts like a window you can see through to part of the scroll view's content below.
将Scrollview视为屏幕滑动*的大视图表面。您可以将子视图添加到滚动视图,然后滚动就像将屏幕放在滚动视图上一样 - 屏幕就像一个窗口,您可以看到下面滚动视图的部分内容。
To do this, a scrollview has a few extra properties over a normal UIView - but it is like a UIView in one imprtant respect: it doesn't render any content directly itself. You need to add a subview to draw your text. A scrollview is set up and displayed in exactly the same way as a UIView - i.e. you set the frame add it to another view and to show your text you need to add subviews to the UIScrollView that can actualy render the text.
要做到这一点,scrollview在普通的UIView上有一些额外的属性 - 但它在一个重要的方面就像一个UIView:它不直接呈现任何内容。您需要添加子视图来绘制文本。滚动视图的设置和显示方式与UIView完全相同 - 即您设置框架将其添加到另一个视图并显示您需要将子视图添加到UIScrollView的文本,该视图可以实际渲染文本。
In order to set up a basic UIScrollView you request, you should just create it like a normal full screen view - set the frame to be the same size as the window and add the scrollview to the window as a subview. Then make a large UITextView to hold your text. The UIText view can be as large as you like - specifically it can be bigger than the screen. set the contentSize property of the UIScrollView to be the same as the frame of the UITextView and then add the UIText view as a subview of the UIScrollView.
为了设置您请求的基本UIScrollView,您应该像普通的全屏视图一样创建它 - 将框架设置为与窗口相同的大小,并将scrollview作为子视图添加到窗口中。然后制作一个大的UITextView来保存你的文字。 UIText视图可以随意大小 - 特别是它可以比屏幕大。将UIScrollView的contentSize属性设置为与UITextView的框架相同,然后将UIText视图添加为UIScrollView的子视图。
Once you have this working, you can move the content automatically with the contentOffset property, controll zooming and set up a delegate to observe scrolling events.
完成此操作后,您可以使用contentOffset属性自动移动内容,控制缩放并设置委托以观察滚动事件。
* more accurately, over which the frame slides but I'm assuming you are making a full screen UIScrollView. I'm sure you can generalise it if you want a smaller view.
*更准确地说,框架滑动,但我假设你正在制作全屏UIScrollView。如果你想要一个较小的视图,我相信你可以概括它。
#3
1
I used UIScrollView this way for an instructions pane in one of my applications. It worked but I was unhappy with the result. I then switched to using a UIWebView and have been much happier with the result. It handles sizing the scroll view automatically, I get all the formatting capabilities of HTML and I can have links that go to additional information (or external sites) with no more than adding another HTML file and maybe some delegate code. Here is the code I used (and I added the HTML file to my app as a resource):
我以这种方式使用UIScrollView作为我的一个应用程序中的指令窗格。它有效,但我对结果不满意。然后我转而使用UIWebView,对结果感到非常满意。它自动处理滚动视图的大小,我获得了HTML的所有格式化功能,我可以拥有链接到其他信息(或外部网站),只需添加另一个HTML文件和一些委托代码。这是我使用的代码(我将HTML文件作为资源添加到我的应用程序中):
NSString *path = [[NSBundle mainBundle] pathForResource:@"instructions" ofType:@"html"];
NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];
NSString *htmlString = [[NSString alloc] initWithData: [readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];
[self.instructionsView loadHTMLString:htmlString baseURL:nil];
#4
1
U may refer to this website http://www.edumobile.org/iphone/iphone-programming-tutorials/scrollview-example-in-iphone/
你可以参考这个网站http://www.edumobile.org/iphone/iphone-programming-tutorials/scrollview-example-in-iphone/
U follow the step by step to make the scroll view in iphone...good luck:)
你按照一步一步在iPhone上制作滚动视图...祝你好运:)
#1
10
You can just use a UITextView. It's a child of UIScrollView, and if you set it's text property to an amount of text that does not fit within it's frame, the view will become scrollable.
你可以使用UITextView。它是UIScrollView的子项,如果将其text属性设置为不适合其框架的文本量,则视图将变为可滚动。
#2
21
Apple's UIScollView documentation is quite good, you should start there and understand the class.
Apple的UIScollView文档相当不错,你应该从那里开始理解这门课程。
Think of a Scrollview as a large view surface over which the screen slides*. You can add subviews to the scrollview and then scrolling is like positioning the screen over the scrollview - the screen acts like a window you can see through to part of the scroll view's content below.
将Scrollview视为屏幕滑动*的大视图表面。您可以将子视图添加到滚动视图,然后滚动就像将屏幕放在滚动视图上一样 - 屏幕就像一个窗口,您可以看到下面滚动视图的部分内容。
To do this, a scrollview has a few extra properties over a normal UIView - but it is like a UIView in one imprtant respect: it doesn't render any content directly itself. You need to add a subview to draw your text. A scrollview is set up and displayed in exactly the same way as a UIView - i.e. you set the frame add it to another view and to show your text you need to add subviews to the UIScrollView that can actualy render the text.
要做到这一点,scrollview在普通的UIView上有一些额外的属性 - 但它在一个重要的方面就像一个UIView:它不直接呈现任何内容。您需要添加子视图来绘制文本。滚动视图的设置和显示方式与UIView完全相同 - 即您设置框架将其添加到另一个视图并显示您需要将子视图添加到UIScrollView的文本,该视图可以实际渲染文本。
In order to set up a basic UIScrollView you request, you should just create it like a normal full screen view - set the frame to be the same size as the window and add the scrollview to the window as a subview. Then make a large UITextView to hold your text. The UIText view can be as large as you like - specifically it can be bigger than the screen. set the contentSize property of the UIScrollView to be the same as the frame of the UITextView and then add the UIText view as a subview of the UIScrollView.
为了设置您请求的基本UIScrollView,您应该像普通的全屏视图一样创建它 - 将框架设置为与窗口相同的大小,并将scrollview作为子视图添加到窗口中。然后制作一个大的UITextView来保存你的文字。 UIText视图可以随意大小 - 特别是它可以比屏幕大。将UIScrollView的contentSize属性设置为与UITextView的框架相同,然后将UIText视图添加为UIScrollView的子视图。
Once you have this working, you can move the content automatically with the contentOffset property, controll zooming and set up a delegate to observe scrolling events.
完成此操作后,您可以使用contentOffset属性自动移动内容,控制缩放并设置委托以观察滚动事件。
* more accurately, over which the frame slides but I'm assuming you are making a full screen UIScrollView. I'm sure you can generalise it if you want a smaller view.
*更准确地说,框架滑动,但我假设你正在制作全屏UIScrollView。如果你想要一个较小的视图,我相信你可以概括它。
#3
1
I used UIScrollView this way for an instructions pane in one of my applications. It worked but I was unhappy with the result. I then switched to using a UIWebView and have been much happier with the result. It handles sizing the scroll view automatically, I get all the formatting capabilities of HTML and I can have links that go to additional information (or external sites) with no more than adding another HTML file and maybe some delegate code. Here is the code I used (and I added the HTML file to my app as a resource):
我以这种方式使用UIScrollView作为我的一个应用程序中的指令窗格。它有效,但我对结果不满意。然后我转而使用UIWebView,对结果感到非常满意。它自动处理滚动视图的大小,我获得了HTML的所有格式化功能,我可以拥有链接到其他信息(或外部网站),只需添加另一个HTML文件和一些委托代码。这是我使用的代码(我将HTML文件作为资源添加到我的应用程序中):
NSString *path = [[NSBundle mainBundle] pathForResource:@"instructions" ofType:@"html"];
NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];
NSString *htmlString = [[NSString alloc] initWithData: [readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];
[self.instructionsView loadHTMLString:htmlString baseURL:nil];
#4
1
U may refer to this website http://www.edumobile.org/iphone/iphone-programming-tutorials/scrollview-example-in-iphone/
你可以参考这个网站http://www.edumobile.org/iphone/iphone-programming-tutorials/scrollview-example-in-iphone/
U follow the step by step to make the scroll view in iphone...good luck:)
你按照一步一步在iPhone上制作滚动视图...祝你好运:)