iPhone: UITextView wrap around UIImage?

后端 未结 3 1336
时光说笑
时光说笑 2020-12-19 05:31

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

The image size is

相关标签:
3条回答
  • 2020-12-19 06:14

    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

    0 讨论(0)
  • 2020-12-19 06:20

    Gil's answer in Swift:

    let exclusionPath = UIBezierPath(rect: CGRectMake(0, 0, 100, 100))
    self.textView.textContainer.exclusionPaths = [exclusionPath]
    
    0 讨论(0)
  • 2020-12-19 06:37

    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]
    
    0 讨论(0)
提交回复
热议问题