How to use scroll view on iPhone?
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?
- Scroll View in my app doesn't work on iOS 11
- How to highlight CoreText with changing highlight colors?
- Programmatically scroll a UIScrollView
- How to Add HeaderView from nib to UiTableView programmatically in Swift
- UIScrollView inside UIScrollView
- Dynamic UILabel height inside UIScrollView with Autolayout
4 Solutions Collect From Internet About “How to use scroll view on iPhone?”
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.
Apple’s UIScollView documentation is quite good, you should start there and understand the class.
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.
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.
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.
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.
* 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.
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):
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];
- App failing to load
- Apply NSPredicate on
- How to sort NSArray of objects based on one attribute
- Is there a way to have Xcode 5 autocomplete like Visual Studio?
- zbar SDK dont work for armv7s(iPad 4 iOS 7)
- How to detect if any external libraries are calling uniqueIdentifier]?
- Zoom in and Out through a NSView or Magnify
- UISearchController Not Redisplaying Navigation Bar on Rotate
- Cordova iOS location message
- Assigning to self in Objective-C
- How to change font of UIButton with Swift
- jpeg2000 on ios app
- why am I getting “non-aggregate cannot be initialized with initializer list”
- How to clean build folder in Xcode 5?
- UILabel with a hyperlink inside a UITableViewCell should open safari webbrowser?