What im tyring to create is an application the utilizes book features like when the user drags a touch or just touches the right screen the page turns, the book im trying to create has atleats 300 pages. What i need is a starting point on how to access the text data and display it on a view. When the user changes the page the next set of text is accesed and displayed. How would i be able to model a book with so many pages?
any help is appreciated
PS: ive tried looking for simple tutorials but no luck
If you have your text data in a .txt file then you can extract it from there first of all. This post gives info on how you can do that.
Then every time you flick the page just load in an appropriate substring from the entire text. This would be best in an uneditable UITextView. It could look something like this:
int maxCharPerPage = 200;
int lastCharPreviousPage = 1000;
NSRange thisPageRange = NSMakeRange(lastCharPreviousPage+1, lastCharPreviousPage+1+maxCharPerPage);
NSString *thisPageText = [entireBookText substringWithRange:thisPageRange];
textView.text = thisPageText;
Or you could use a UILabel on top of a view but this approach isn't really what UILabel is designed for.
Related
In my app i am using UIWebView for displaying the pdf from an External url. Its get loaded perfectly. While scrolling page number is displayed inside a box. Is there any way to get the page number in code?
You can use the next code:
- (int)getActualPage
{
float scrollViewHeight = self.webView.frame.size.height;
float pageOffset = self.webView.scrollView.contentOffset.y;
return ((int)pageOffset / (int)scrollViewHeight)+1;
}
This code gives you the page number of the document when you see the full page on the UIScrollView. If you want to get the same page number that the UIWebView gives you, just change the final operation. I think that using the module you can get what you want. I know it's not the perfect solution but it's the best I got.
So I have 2 apps. One is a sensors app (built with XCode) that records data (text) with hardware wireless sensors. The other is a checklist/reference manual (built with Titaniam Appcelerator). Using custom URL schemes, they can instantiate each other.
What I am trying to do is paste any text data the sensors app copies to the clipboard into a text field in the reference manual app. I have a UIWebview showing html pages (the checklist) with a text box displayed now. To demo the capability, I have to touch the field and select paste. I was thinking that javascript might work, but all my research poo poo's that idea. Any thoughts about how to grab the text that is on the clipboard and display it programmatically in the reference manual app without having to touch the field and select paste?
Should I even be looking at the clipboard or should I be looking into modifying the custom URL scheme to pass data that way instead?
To get the text from the clipboard:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString *string = pasteboard.string;
if (string) {
// Do something
}
For more funcional communication between apps, take a look at URL Schemes.
So, I figured out a way to pass the data in the url with this tutorial. At the bottom it describes how to pass data after you set up the URL id for each app. Hope this helps someone.
Pasting in Swift
Get the pasteboard string with UIPasteboard.generalPasteboard().string.
The string is optional, so it must be unwrapped before being used.
if let pasteboardString = UIPasteboard.generalPasteboard().string {
// use the string, for example:
myTextView.insertText(pasteboardString)
}
Note
The original question is asking for something more complex than this. However, most people come here based on the question title rather than question content, so that I what I am answering here.
I would like to be able to format a URL in my UITextField nicely. So say the text of the UITextField is
textField.text = #"Hi this is a page for my website http://www.mywebsite.com";
I would like it to automatically underline this mark it as a hyperlink and when a user taps on the link it opens up the site. This is similar to any twitter client that you have out there (tweetdeck, tweetbot, etc). How do I do this the easy way?
You can use a UITextView instead and set the dataDetectorTypes property to the types of links you want to be able to handle.
hey this is really simple, you can set the UITextFiled to detect Links, like so:
myTextView.dataDetectorTypes = UIDataDetectorTypeAll
check out my tutorial on this at my site for more info
http://www.sdkboy.com
I want to update a huge text file in UITextView. But the device just hangs or crashes some times. The text file size is 4MB.
The UITextView is been added from Interface Builder.
I am loading the file from document directory.
Below is the code for loading the text file:-
NSError *err = nil;
txtView.text =[NSString stringWithContentsOfFile:documentPath encoding:NSUTF8StringEncoding error:&err];
As I want to edit the file I cannot load it in WebView which is much faster and it works properly.
Is there any way were I can only partially load the text File(one page at a time) so it doesn't take much time to load or some other way to load the whole file properly ?
Any hint in right direction would be highly appreciated.
.
Sounds like a nasty problem, because you would have to measure how much text has to fit exactly in one page. You could try and play around with the UIScrollView-properties and delegate methods of the textview (like contentOffset), but I would not recommend it.
Personally, I would try to divide the text content into multiple pages (multiple NSStrings) and then use two buttons "next", "previous" to switch between pages within the text view.
Store each line of your data in an Array and use array as data source of UITableView, rest of the things will be handled by UItableview
I am pretty new to this iPhone dev thing but so far I have built a pretty good app but I have stumbled into this problem that for the life of me I cannot seem to solve.
Basically the app is a chat application for social site. Everything is working 100% except the input box which currently is a UITextbox. This works fine however I would like the box to grow and be a multiline UITextbox with scroll. I replaced the UITextbox with a UITextview and all is good. I have the UITextview expanding as the user enters text however I have one slight problem that is driving me nuts.
When the UITextview gets focus it shifts the cursor and any text in there up just out of view. The UITextview I have set to display 2 lines by default and then as the height of the text goes beyond those two lines I would like the box to grown (which it does) and the text to remain scrolled up so you can see what you are typing. If you look at the SMS app on the iPhone this is exactly how I would like it work.
Any words of wisdom would be greatly appreciated.
I think Blaenk answered perfectly (that was going to be my answer). But just in case you don't want to include Three20 in your project (it's kinda big), below is the relevant code from TTTextEditor. You should be able to call this from wherever you are expanding the text view.
- (void)scrollContainerToCursor:(UIScrollView*)scrollView {
if (_textView.hasText) {
if (scrollView.contentSize.height > scrollView.height) {
NSRange range = _textView.selectedRange;
if (range.location == _textView.text.length) {
[scrollView scrollRectToVisible:CGRectMake(0,scrollView.contentSize.height-1,1,1)
animated:NO];
}
} else {
[scrollView scrollRectToVisible:CGRectMake(0,0,1,1) animated:NO];
}
}
}
Check out three20:
Three20 is a collection of iPhone UI classes, like a photo viewer, and general utilities, like an HTTP disk cache. Three20 is derived from the Facebook iPhone app, which is one of the most downloaded iPhone apps ever.
Specifically, you'll want to take a look at TTTextEditor:
TTTextEditor is a UITextView which can grow in height automatically as you type. I use this for entering messages in Facebook Chat, and it behaves similarly to the editor in Apple's SMS app.
You'll find instructions on how to add three20 to your project here.
I made a subclass of UITextView just for that:
https://github.com/MatejBalantic/MBAutoGrowingTextView
It is an auto-layout based light-weight UITextView subclass which automatically grows and shrinks based on the size of user input and can be constrained by maximal and minimal height - all without a single line of code.
The class is made primarily for use in Interface builder and only works with Auto layout.