views:

61

answers:

3

Hi everyone,

I would like to have a text in a text... I mean like in the newspaper: when there is a picture, the text fits and follow the border of the picture. For example: http://en.wikipedia.org/wiki/Iphone look at the pictures... the text follows them!

Is it possible to do that on the iPhone?

Thanks in advance

+2  A: 

You can achieve this fairly easily with a UIWebView and traditional web techniques.

If you want to have it happen in Cocoa directly, you're going to have to dive into the more advanced CoreText APIs, which will probably be a lot of work.

Andrew Pouliot
mmmhhh... I really wanted it in cocoa! It displays faster.
ncohen
You both mean Cocoa Touch if you're talking about programming the iPhone.
Peter Hosey
A: 

It's called text wrapping or, in CSS/HTML speak, "floating" an image. The best way to do it is probably to have a UIWebView and programmatically dump HTML and CSS into it.

The HTML looks like this:

<img src="IMAGE_URL" style="float:right; margin:6px;" />
<p>My block of arbitrary test. Blah blah blah. Etc.</p>

Here's an example of how to use UIWebView with a string of HTML:

http://iphoneincubator.com/blog/windows-views/display-rich-text-using-a-uiwebview

redwall_hp
That's exactly what Andrew Pouliot said...
ncohen
Sorry, I was looking for a link and making an edit. I realized that my initial comment was virtually the same after I made it. :/
redwall_hp
thx... the thing is that it's slower with UIWebView
ncohen
A: 

Maybe I'm missing something, but why not use subviews? Have a UIView containing a UIImage and UILabel in case of a static text or a non-editable UITextView in case of dynamic amount of text and set their properties to be aligned to the parent view's boundaries.
If you still want to take the low-level path, google for CGContextShowTextAtPoint.
You may also check out this: http://code.google.com/p/core-plot/source/browse/framework/Source/CPTextLayer.h

DenTheMan
how do you align to the parent view's boundaries? I was only able to make the frame a simple rectangle...
ncohen