iphone - 如何实现“浮动”的效果为图像,就像在CSS样式 [英] iphone - How to implement the effect of "float" for image, just like in CSS style
问题描述
在HTML中,使用CSS,可以对图片执行float操作,如下所示:
图片被文字包围。
$ b
$ b
我不能使用UIWebview,因为
$ b $-
加载HTML后,UIWebView有一点滞后。其内容不会立即显示,不像UILabel或UIImage
-
映像是异步加载的,所以我需要一个空白处, p>
这是可能的,我只是使用UIImageView&
简单的方式可能是使用两个标签和图片。如果您的文本/图像是静态的,那么您可以在正确的地方拆分文本。如果没有,你必须做一些文本大小测量;请参见 UIStringDrawing.h 。
硬的方式是使用 text创建你自己的UIView子类
和 image
属性,让它做所有的字符串/图像布局和绘图。
更难的方式是使用Core Text(iOS 3.2+); Columnar Layout 示例应该可以工作,但还要注意, CTFramesetterCreateFrame()
可以采用任意的CGPath,通过它的可用区域的路径。这可能实际上比使用UIKit字符串大小更容易,并试图找出所有的换行符在哪里(你只需要写大量的核心文本样板代替)。
In HTML, with CSS, one can do "float" for images, just like this
the image is surrounded by text.
How can I do it WITHOUT UIWebView?
I can't use UIWebview, because
UIWebView has a slight lag after you loadHTML. Its content doesn't show immediately, not like UILabel or UIImage
The image is async loaded, so I need a white space holder there with UIActivityView spinning
Is that possible I just use a UIImageView & UILabel to do float?
Thanks
The "easy" way is probably to use two labels and an image. If your text/images are static, then you can split the text at the right place beforehand. If not, you'll have to do some text size measurements; see UIStringDrawing.h. Figuring out where all the line breaks should be is non-trivial.
The "hard" way is to create your own subclass of UIView with text
and image
properties and have it do all the string/image layout and drawing. It's not actually that much harder than figuring out where the line breaks should be dynamically.
The "harder" way is to use Core Text (iOS 3.2+); the Columnar Layout example in the Core Text Programming Guide should work, but also note that CTFramesetterCreateFrame()
can take an arbitrary CGPath, so you can just pass it a path of the available area. This might actually be slightly easier than using UIKit string-sizing and trying to find out where all the line breaks are (you just need to write a lot of Core Text boilerplate instead).
这篇关于iphone - 如何实现“浮动”的效果为图像,就像在CSS样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!