How to insert and delete image and text in one view just like MMS apps on iPhone - iphone

I would like to implement something like MMS app on iPhone, where user will have an option to include an image and text.
The way I did is i created a UIUiew and included a UITextView and UIImageView inside it, and when user selects an image it goes in to the UIImageView and the user can type in the UITextView.
But the problem that I am facing is once you insert a UIImage how do you put a cursor after the image so that user can delete(backspace) the image and that space free's up and it becomes available for the user to type in more text.

Simple answer: You cannot mix text and images in a UITextView. If you want to achieve a behavior like this, you should look into using Core Text to render the text yourself (it supports other elements inside the text via certain callbacks through which you tell the text system how much space it is supposed to reserve for the image.
To make the text editable, you would have to implement the text editing protocols UITextInput and UIKeyInput. Which means you have to basically write your own text editor. It's possible but it's a lot of work.

Related

Scrollable view with text and ability to do something when specific phrase is tapped

I am trying to implement a view which will load text from sqlite database (every sentence in a text will have unique tag in database) and will allow to execute some code while sentence is clicked (on-click executed method should then scroll clicked sentence to the center of the screen and change it's color/background color/font size to emphasize it)
Is it possible without using webview and js/js-native bridge? Which approach should be taken to implement such a view? Any help and comments highly appreciated!
Hmm, you could also considering using NSAttributedString together the Core Text Framework and attribute each sentence and attach some extra info about. Next you lookup the attribute below the tap position of the view. Once you have that you can retrieve the extra info again and do whatever you want with the tap.
After the tap you could then alter the properties of that part of the text. E.g. different font colour etc.
This tutorial on the internet looked interesting:
http://www.raywenderlich.com/4147/how-to-create-a-simple-magazine-app-with-core-text

How can I display structured text?

I have some text that I need to load from an XML file. The idea is to be able to make the text interactive. I should be able to tell when a user taps a piece of the text, like in the WordWeb app. I know this seems to be the kind of job that a UIWebView is for but I want to avoid generating HTML and implementing handlers for the hrefs. I hope that made any sense.
Another way could be using a UITableView with UITextViews or UILabels as content views for the cells. However, I couldn't find out how we can customize the appearance of the table view, add a border to the view for example.
The end result expected is a view that looks like a page from a book but pieces of the displayed text can be tapped and bookmarked etc.
Am I even thinking in the right direction?

Should I use UIWebView or UITextView to display text in an e-book reader app?

I want to make an e-book reader iPhone app. Should I use UITextView or UIWebView to display the text? Which control is used by other e-book readers?
I would use a UIWebView, as it gives you much more flexibility in the presentation of the text. According to the UITextView Class Reference:
This class does not support multiple
styles for text. The font, color, and
text alignment attributes you specify
always apply to the entire contents of
the text view. To display more complex
styling in your application, you need
to use a UIWebView object and render
your content using HTML.
Also, UITextView uses scrolling to display large amounts of text (it inherits from UIScrollView); in an e-book reader, you will most likely want to paginate the content, so you will not want the scrolling behaviour.
UIWebView is much better solution than UITextView mainly due to support of rich formatting of its contents. On the other hand you will miss some very important functions which you get for free while using UITextView. I'm talking mostly about searching inside, changing contents size etc. All of this is possible with UIWebView but it's not straightforward - css & javascript are for the help here
Did you get highlight functionality for this as font size can change. Save them for future so that when ever he came to same page can see them
U should use UIWEB view ,as to provide paragraph and other functions of text are not supported by text view, u can directly implement html code and can make the app with proper view of text. So my suggestion is to use web view.

Cocoa Touch text view with aligned, justified text

I am trying to create a textview with predefined height that will contain justified text.
When entering the text into the view, I need to be able to check when the view is full.
How would I do this? Core Text?
I am using sdk-3.2.
You cannot do it using UITextView (that would be the most "logical" way to do it), or any others SDK current classes.
The only simple way to do it if to put the content to be justified in an html file, justify it using CSS, and show it in a UIWebView.

Large scrollview table with buttons

We are trying to write a training manual application for the iPhone. On the top half of the screen is a diagram of a car engine, on the bottom half is some text. At the user repeatedly hits a "next" button, we highlight different parts of the engine, and in concert we highlight different parts of the descriptive text below.
We basically want "living text" in the text half, with the illustration following along on top to where the reader is in the text. What we'd like from the text is 1. user can scroll it using their thumb so possibly a UIScrollView 2. the software can explicitly drive a scroll to any part of the text (when they hit the "next" button). 3. the words in the text are interspersed with hotlinks e.g. "this is the camshaft... this is the piston..." and the user should be able to click on any of the keywords like camshaft, piston, and have the diagram highlight that. (The problem is not highlighting the diagram, its capturing the click). The text would have 300~400 buttons/links/keywords and about 600 words of text.
Since this is fairly similar to using a web browser, we tried using Apple's version of webkit using a UIWebView and handleOpenURL to register a service back to the app itself. But Webkit for internal links a popup comes up asking permission to access that link. Every single the user wants to go to a link (in our case just an internal event that we'd intercept so that we can highlight e.g. the camshaft). Tried to intercept the event from the HTML view, but that didn't work.
It seems like the best we can do is to abandon scrolling text, and make the text part more like flash cards or a power point presentation, breaking the text into custom UIViewCells with buttons inside a UIScrollView. However, this would impose an annoying constraint on the author that they would have to write everything to fit in the UIViewCells, sort of chunky.
Any ideas would be appreciated.
This is definitely something you can use a UIWebView for. Don't use handleOpenURL, rather, set your viewController as the webview's delegate, and override -webView:shouldStartLoadWithRequest:navigationType:. When this gets called, check the request, and pull out your link data from there.
It would probably be easier to implement that completely in JavaScript in the document you load in a UIWebView. You would have to use JavaScript (i.e. [UIWebView stringbyevaluatingjavascriptfromstring:]) anyway to achieve things like scrolling to a certain position.