Iphone - How to implement the effect of "float" for the image, as in the style of CSS

In HTML, with CSS, you can do "float" for images, just like

Float effect for image and text

The image is surrounded by text.

How to do it WITHOUT UIWebView ?

I can not use UIWebview because

  • UIWebView has a slight delay after loading HTML. Its contents are not displayed immediately, and not as UILabel or UIImage

  • The image is loaded async, so I need a white space holder with rotation UIActivityView

Is it possible that I'm just using UIImageView and UILabel to do a float ?

thanks

+2
iphone css-float
source share
1 answer

The easy way is probably to use two tags and an image. If your text / images are static, you can split the text in the right place in advance. If not, you will need to take some text size measurements; see UIStringDrawing.h . Find out where all line breaks should be nontrivial.

The "hard" way is to create your own subclass of UIView with the text and image parameters, and it will do all the layout and drawing of the line / image. This is actually not much more complicated than figuring out where the line break should be dynamically.

A tougher way is to use Core Text (iOS 3.2+); you should use the Columnar Layout in the body text programming guide, but also note that CTFramesetterCreateFrame() can accept arbitrary CGPath, so you can just go through this path of the available area. It might be a little easier than using UIKit string calibration and trying to figure out where all the line breaks are (you just need to write a lot of Core Text templates).

+1
source share

All Articles