iPhone:UITextView 环绕 UIImage?

发布于 2024-10-06 15:45:52 字数 127 浏览 0 评论 0原文

如何让 UITextView 将其文本包裹在 UIImage 周围,如下图所示? alt text

图像大小之前不一定已知。

How do I get a UITextView to wrap its text around a UIImage like in this image?
alt text

The image size is not necessarily previously known.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烟─花易冷 2024-10-13 15:45:52

iOS 7 及更高版本:

UIBezierPath * imgRect = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 100, 100)];
self.textView.textContainer.exclusionPaths = @[imgRect];

Swift(归功于 Bart van Kuik):

let exclusionPath = UIBezierPath(rect: CGRectMake(0, 0, 100, 100))
self.textView.textContainer.exclusionPaths = [exclusionPath]

IOS 7 and above:

UIBezierPath * imgRect = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 100, 100)];
self.textView.textContainer.exclusionPaths = @[imgRect];

Swift (credit to Bart van Kuik):

let exclusionPath = UIBezierPath(rect: CGRectMake(0, 0, 100, 100))
self.textView.textContainer.exclusionPaths = [exclusionPath]
小瓶盖 2024-10-13 15:45:52

Gil 在 Swift 中的回答:

let exclusionPath = UIBezierPath(rect: CGRectMake(0, 0, 100, 100))
self.textView.textContainer.exclusionPaths = [exclusionPath]

Gil's answer in Swift:

let exclusionPath = UIBezierPath(rect: CGRectMake(0, 0, 100, 100))
self.textView.textContainer.exclusionPaths = [exclusionPath]
没企图 2024-10-13 15:45:52

如果有人有更好的解决方案,请提出来,但我通常不得不恢复到 html 来完成这种技巧。

您可以使用两个 textView 和一个 imageView 以编程方式实现此目的,但我将编写一些 LOC。您必须计算出图像的大小,将第一个表格视图设置为适合旁边,而不是计算出字符串比可见长度长的位置,将其剪掉并继续下一个文本视图。

通过简单的本地 UIWebView 也可以实现相同的效果

If somebody has a better solution, please bring it on, but i usually had to revert to html to do this kind of trick.

You could use two textViews and one imageView to achieve this programmatically, but i'll be a couple of LOC to write. You would have to figure out the size of the image, set the first table view to fit nicely next to, than figure out where the string is longer than visible, cut it off an go on on the next textView.

The same could be achieved by a simple local UIWebView

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文