开发者

iPhone - A text in a text

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开发者_Python百科 to do that on the iPhone?

Thanks in advance


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜